【问题标题】:Changing schemaLocation in WSDL更改 WSDL 中的 schemaLocation
【发布时间】:2016-10-10 12:30:01
【问题描述】:

我有一个 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 导致另一个错误

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

然后我将地址添加到我的端点,将其更改为

<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 不匹配。这可能是因为合同不匹配 (发送方和接收方之间的操作不匹配)或绑定/安全不匹配 发送者和接收者。检查发送方和接收方是否具有相同的合同和 相同的绑定(包括安全要求,例如消息、传输、无) [/代码]

谁能帮忙?

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

}

【问题讨论】:

  • 可以分享一下服务接口和配置文件(endpoint tag)吗?
  • 我添加了 web.config 部分和界面。非常感谢您的帮助!

标签: wcf xsd wsdl


【解决方案1】:

通过改变解决了问题

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

【讨论】:

    【解决方案2】:

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

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

    您应该使用HttpClientWebClient 调用您的服务。

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

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

    【讨论】:

    • 我应该使用不同类型的绑定吗?我只是在浏览器中调用它来测试它生成的 xml,它是无效的
    • @ElenaDBA 如果您希望能够使用 WSDL 来描述您的服务,您应该使用像 wsHttpBinding 这样的 SOAP 绑定。如果使用者应用程序也不是 WCF,那么您应该使用 basicHttpBinding。但是,使用 RESTful 服务实际上比使用 SOAP 服务要容易得多。
    • @ElenaDBA - 事实上,我可以在您的 system.serviceModel 配置中看到您有一个用于 basicHttpBinding 的绑定配置部分。我假设在过去的某个时候,有一个端点暴露在基本 HTTP 上。
    • @TomRedfem,你是对的。我将绑定改回 basicHttpBinding,但我仍然遇到同样的问题。知道如何解决吗?显然,在这种情况下,服务器 IP 地址与网站地址不同,这可能会导致问题,
    • @ElenaDBA 是您无法使用 ?wsdl 地址从操作中生成客户端代码的问题吗?你能打电话给服务吗?
    猜你喜欢
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多