在 WSDL 中更改 schemaLocation

Changing schemaLocation in WSDL

我有一个 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

我收到 "Page cannot be displayed" 错误,如果我在 Chrome 调试工具中使用网络选项卡,它会显示调用已中止。但是如果我尝试在

访问模式

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

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

要更改,我在配置文件中添加了 httpsGetURL:

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

导致错误:

A registration already exists for URI

我可以通过在 .svc 之后添加 /mex 来摆脱它。奇怪的是我没有 mex 端点,因为由于禁用匿名身份验证我无法使用它。

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

The message with To 'https://alias.sys.domain.com/ProjectName/MyService.svc/mex?wsdl' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.

然后我将地址添加到我的端点,将其从

<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

将我的错误更改为

The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None) [/code]

有人可以帮忙吗?

<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);

}

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

WSDL 仅适用于基于 SOAP 的操作。您正在通过纯 HTTP 公开您的操作。

您应该使用 HttpClient or WebClient 调用您的服务。

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

Microsoft 应该删除 webHttpBinding 的元数据功能,因为它具有误导性。他们没有是一个信号,您可能应该放弃 WCF 以进行 RESTful 操作并使用 Nancy 或 ASP.Net WebAPI。

通过更改解决了问题

<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>