WCF使用反向代理 [英] WCF using Reverse proxy

查看:62
本文介绍了WCF使用反向代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉很长的帖子...我们在组织内部使用了.Net 4.0编写的WCF服务.最近,需要使此服务在组织网络外部可用.因此,网络人员使用反向代理使该服务在组织外部可用.这是图片的设置方式.

您可以在图片中看到..服务我收到如下错误.

错误:无法从 https://mywebsite.com/readd.svc 如果这是Windows(R)您可以访问的Communication Foundation服务,请检查您是否具有在指定地址启用了元数据发布.要获得启用元数据发布的帮助,请参阅 http://go.microsoft.com/上的MSDN文档.fwlink/?LinkId = 65455.WS-Metadata 交换错误URI: http://mywebsite.com/readd.svc 元数据包含无法解析的引用:" https://mywebsite.com/readd.svc ".内容类型application/soap + xml;不支持charset = utf-8通过服务 https://mywebsite.com/readd.svc .
客户端和服务绑定可能不匹配.
远程服务器返回错误:(415)OK.HTTPGET错误
URI: https://mywebsite.com/readd.svc
无法识别网址为 http://mywebsite.com/readd.svc 的文档作为已知的文档类型.每种已知类型的错误消息都可以为您提供帮助解决问题:-来自"XML架构"的报告是无法识别文档格式(内容类型为'text/html; charset = UTF-8')."-来自" http://mywebsite.com/readd.svc 的报告是无法识别文档格式(内容类型为'text/html; charset = UTF-8')."-"DISCO文档"中的报告为下载' http://mywebsite.com/readd时出错.svc?disco '.'.--请求失败,HTTP状态为404:找不到.-来自"WSDL文档"的报告为无法识别文档格式(内容类型为'text/html; charset = UTF-8')."."

网络人员通知我要以https形式提供服务.这是我的web.config文件

 <行为>< serviceBehaviors>< behavior name ="ServiceLookup.LookupServiceBehavior">< serviceMetadata httpGetEnabled ="true" httpGetUrl ="/>< serviceDebug includeExceptionDetailInFaults ="true"/>< dataContractSerializer maxItemsInObjectGraph ="2147483647"/></行为></serviceBehaviors></行为><服务>< service behaviorConfiguration ="ServiceLookup.LookupServiceBehavior" name ="SmallApp.ServiceLookUp.LookUpService">< endpoint address =" binding ="basicHttpBinding" bindingConfiguration ="BSBindingConfig" name ="SmallApplianceBSEndPoint"contract ="SmallApp.ServiceLookUp.ILookupService"/><端点地址="mex" binding ="mexHttpBinding" contract ="IMetadataExchange"/></service></services><!-在部署过程中将其删除-><!-< serviceHostingEnvironment multipleSiteBindingsEnabled ="true"/>-> 

您能建议我如何解决这个问题..以便组织外部的用户可以使用WCFTestCleint作为http/https访问api.

更新的web.config文件

 </binding></basicHttpBinding></bindings><行为>< serviceBehaviors>< behavior name ="ServiceLookup.LookupServiceBehavior">< serviceMetadata httpGetEnabled ="true" httpGetUrl =" httpsGetEnabled ="true"/>< serviceDebug includeExceptionDetailInFaults ="true"/>< dataContractSerializer maxItemsInObjectGraph ="2147483647"/></行为></serviceBehaviors></行为><服务>< service behaviorConfiguration ="ServiceLookup.LookupServiceBehavior" name ="SmallApp.ServiceLookUp.LookUpService">< endpoint address =" binding ="basicHttpBinding" bindingConfiguration ="BSBindingConfig" name ="SmallApplianceBSEndPoint"contract ="SmallApp.ServiceLookUp.ILookupService"/><端点地址="mex" binding ="mexHttpBinding" contract ="IMetadataExchange"/><端点地址="mex" binding ="mexHttpsBinding" contract ="IMetadataExchange"/></service></services><!-在部署过程中将其删除->< serviceHostingEnvironment multipleSiteBindingsEnabled ="true"/> 

我仍然在组织网络外部以http或https身份访问时仍然出错

解决方案

WSDL通常根据模型的元数据,属性和主机位置动态生成.因此,如果将wsdl代理到另一个环境,它将出现问题.

>strong> servicemetadata 用于指定 externalMetadataLocation :

一个Uri,其中包含WSDL文件的位置,该文​​件将响应WSDL和MEX请求而不是自动生成的WSDL返回给用户.

添加 externalMetadataLocation 如下:

 < system.serviceModel><行为>< serviceBehaviors><行为>< serviceMetadata httpGetEnabled ="true" httpsGetEnabled ="true" externalMetadataLocation ="https://example.com/SOAP/Service1.wsdl" /></行为></serviceBehaviors></行为></system.serviceModel>  

然后,您可以提前预先生成WSDL,随意进行调整,然后上传修改后的文件作为合同.

进一步阅读

My apologize for long post... We have a WCF service written in .Net 4.0 used internally within the organization. Recently there was a requirement to make this service available outside the organization network. So the network guys used reverse proxy to make this service available outside the organization. Here is the picture how it is set up.

As you can see in the picture..the service http://mywebservice.com/readd.svc is hosted on WIndows 2008 R2 which has a internal IP address as XXX.YYY.ZZZ.RRR. The service is hosted on port 80.

what is the problem ?.

Internally I can access the service as http://mywebservice.com/readd.svc using WCFTestClient and browser. But outside the organization if I type http://mywebservice.com/readd.svc I get "404 file not find error" and in WCFTestCleint I get error as "Error: Cannot obtain Metadata from http://mywebservice.com/readd.svc .........".

However if I type in the service as in browser I get the screen which shows soap link as shown below. Please ignore the LookUpService.svc name mismatch.

As you can see in above figure ...address bar is https , but the soap link is http . If I click the http link http://.... ?wsdl , I get not found error. This is since Reverse proxy only allows connection as https .

If I use WCFTextClient and add servicie as https://mywebsite.com/readd.svc I get error as below.

"Error: Cannot obtain Metadata from https://mywebsite.com/readd.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://mywebsite.com/readd.svc Metadata contains a reference that cannot be resolved: 'https://mywebsite.com/readd.svc'. Content Type application/soap+xml; charset=utf-8 was not supported by service https://mywebsite.com/readd.svc.
The client and service bindings may be mismatched.
The remote server returned an error: (415) OK.HTTP GET Error
URI: https://mywebsite.com/readd.svc
The document at the url http://mywebsite.com/readd.svc was not recognized as a known document type.The error message from each known type may help you fix the problem:- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.- Report from 'http://mywebsite.com/readd.svc' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.- Report from 'DISCO Document' is 'There was an error downloading 'http://mywebsite.com/readd.svc?disco'.'. - The request failed with HTTP status 404: Not Found.- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'. "

I was informed by network guys to make service available as https. Here is my web.config file

<behaviors>

  <serviceBehaviors>

    <behavior name="ServiceLookup.LookupServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>

  </serviceBehaviors>

</behaviors>

 <services>
    <service behaviorConfiguration="ServiceLookup.LookupServiceBehavior" name="SmallApp.ServiceLookUp.LookUpService">

       <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BSBindingConfig" name="SmallApplianceBSEndPoint"
          contract="SmallApp.ServiceLookUp.ILookupService" />


       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
 </services>
<!-- Remove this during deployment-->
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>-->

Can you suggest how I can resole this issue ..so that users outside organization can access the api with WCFTestCleint as http/https .

Updated web.config file

    </binding>
    </basicHttpBinding>
</bindings>

<behaviors>

  <serviceBehaviors>

    <behavior name="ServiceLookup.LookupServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpGetUrl="" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>

  </serviceBehaviors>

</behaviors>

 <services>
    <service behaviorConfiguration="ServiceLookup.LookupServiceBehavior" name="SmallApp.ServiceLookUp.LookUpService">

       <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BSBindingConfig" name="SmallApplianceBSEndPoint"
          contract="SmallApp.ServiceLookUp.ILookupService" />

       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service>
 </services>
<!-- Remove this during deployment-->
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

I am still gettign error accessing as http or https outside organization network

解决方案

The WSDL is typically generated on the fly based on your models metadata, attributes, and host location. So if the wsdl is then proxied to another environment, it's going to have issues.

One escape hatch in servicemetadata is to specify a externalMetadataLocation:

A Uri that contains the location of a WSDL file, which is returned to the user in response to WSDL and MEX requests instead of the auto-generated WSDL.

Add externalMetadataLocation like this below:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" 
             externalMetadataLocation="https://example.com/SOAP/Service1.wsdl" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

You can then pre-generate your WSDL ahead of time, tweak at will, and upload the modified file to serve as the contract.

Further Reading

这篇关于WCF使用反向代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆