更改WSDL中的schemaLocation



我有一个WCF服务,我需要在一个旧的IIS 6服务器上托管。服务器有一个名称Server1,但也有一个用于网站的别名。显然服务器和网站解析到不同的IP地址。

所以WCF服务路径是

https://alias.sys.domain.com/ProjectName/MyService.svc?wsdl

但是当我查看xml生成时,schemaLocation显示为:

<wsdl:types>
  <xsd:schema targetNamespace="http://tempuri.org/Imports">
     <xsd:import schemaLocation="https://server1.subdomain.domain.com/ProjectName/MyService.svc?xsd=xsd0" namespace="http://tempuri.org/" /> 
     <xsd:import schemaLocation="https://server1.subdomain.domain.com/ProjectName/MyService.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/ProjectName" /> 
     <xsd:import schemaLocation="https://server1.subdomain.domain.com/ProjectName/MyService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" /> 
   </xsd:schema>
</wsdl:types>

如果我尝试访问xml

中指定的模式
https://server1.subdomain.domain.com/ProjectName/MyService.svc?xsd=xsd0

我得到"页面无法显示"错误,如果我在Chrome调试工具中使用网络选项卡,它显示调用已中止。但是如果我尝试访问

https://alias.sys.domain.com/ProjectName/MyService.svc?xsd=xsd0

然后我可以毫无问题地访问它,但不幸的是,这不是该服务使用的。

为了改变这一点,我在配置文件中添加了httpsGetURL:

<serviceMetadata httpGetEnabled="true" httpsGetUrl="https://alias.sys.domain.com/ProjectName/MyService.svc"  />

导致错误:

URI

已经存在注册

,我可以通过在.svc之后加入/mex来消除它。奇怪的是,我没有mex端点,因为我不能使用它,由于禁用匿名身份验证。

但是添加/mex导致另一个错误

To 'https://alias.sys.domain.com/ProjectName/MyService.svc/mex?wsdl'的消息由于EndpointDispatcher上的AddressFilter不匹配,无法在接收端处理。检查发送方和接收方的EndpointAddresses是否一致

然后我给端点添加了address,从

<endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" contract="Projectname.IMyService"/>

<endpoint address="web1" binding="webHttpBinding" bindingConfiguration="webBinding" contract="Projectname.IMyService"/>

并尝试使用

https://alias.sys.domain.com/ProjectName/MyService.svc/web1

将错误更改为

由于ContractFilter的原因,带有"Action"的消息不能在接收端处理EndpointDispatcher中的不匹配。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或绑定/安全不匹配发送者和接收者。检查发送方和接收方是否有相同的合同和相同的绑定(包括安全需求,例如Message, Transport, None)(/代码)

有人能帮忙吗?

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHTTP">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows">
        </transport>
      </security>
    </binding>
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="webBinding">
      <security mode="Transport">
      <transport clientCredentialType="Windows">
        </transport>
      </security>
   </binding>
  </webHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="basicBehavior" name="ProjectName.MyService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" contract="Projectname.IMyService"/>
    <!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />-->
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="basicBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceCredentials>
          <windowsAuthentication includeWindowsGroups="true" allowAnonymousLogons="false">
         </windowsAuthentication>
    </serviceCredentials>-->
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"/>
</system.serviceModel>

,下面是接口:

public interface IMyService
{
    [OperationContract]
    [WebInvoke(UriTemplate = "GetStatus/{groupID}/{groupName}", Method = "GET",
      ResponseFormat = WebMessageFormat.Json,
      RequestFormat = WebMessageFormat.Json,
      BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    string GetStatus(string groupID, string groupName);
}

修改

<services>
  <service behaviorConfiguration="basicBehavior" name="ProjectName.MyService">
     <endpoint address="" binding="webHttpBinding" bindingConfiguration="webBinding" contract="Projectname.IMyService"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="basicBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
  <service behaviorConfiguration="basicBehavior" name="ProjectName.MyService">
     <endpoint address="https://alias.sys.domain.com/ProjectName/MyService.svc" binding="webHttpBinding" bindingConfiguration="webBinding" contract="Projectname.IMyService"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="basicBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" httpsGetUrl="https://alias.sys.domain.com/ProjectName/MyService.svc/ssl"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

您不能使用WSDL使用RESTful服务操作。即使元数据通过?wsdl查询公开,它也不是服务的有效定义。

WSDL仅用于基于SOAP的操作。您是在纯HTTP上公开您的操作。

你应该使用HttpClient或WebClient来调用你的服务。

如果您需要公开元数据,请查看OpenAPI。

微软应该删除webHttpBinding的元数据功能,因为它具有误导性。如果它们没有这样做,那就意味着您可能应该放弃WCF,转而使用rest式操作,而使用Nancy或ASP。净WebAPI。

最新更新