空响应对WCF Web服务与终端自定义地址 [英] Empty Response on WCF Web Service with Custom Addresses on EndPoints

查看:246
本文介绍了空响应对WCF Web服务与终端自定义地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个WCF Web服务和托管它的IIS。在Web.config看起来是这样的:

  [...]
< system.serviceModel>
    <行为>
        < serviceBehaviors>
            <行为名=[命名空间] [ServiceNameBehavior]。>
                < serviceMetadata httpGetEnabled =真httpsGetEnabled =真/>
                < serviceDebug includeExceptionDetailInFaults =真/>
            < /行为>
        < / serviceBehaviors>
    < /行为>

    <服务>
        <服务名=[命名空间] [服务名称]。behaviorConfiguration =[命名空间] [ServiceNameBehavior]。>
            <端点地址=基本的绑定=basicHttpBinding的合同=[命名空间] [IService]/>
            <端点地址=安全绑定=basicHttpsBinding合同=[命名空间] [IService]。/>
        < /服务>
    < /服务>
< /system.serviceModel>
[...]
 

当我访问的http://本地主机/ [命名空间] / [服务名称] .SVC 我得到的通常的Web服务的网页,表示你已经创建了一个服务,要测试它,你应该使用svcutil.exe的调用服务,等等,等等...

现在......问题是,如在web.config中定义,我想使用两种类型的连接这个Web服务(实际上只是限制访问这两个,因此禁用默认 .SVC 通话),但是当我去的http://本地主机/ [命名空间] / [服务名称] .SVC /基本的https://本地主机/ [命名空间] / [服务名称] .SVC /安全我得到一个空白页面,也可以我从本地托管的PHP页面访问服务

这是正常的,这些绑定这样的表现?如果不是这样,我该如何解决这个问题?


更新1


我也注意到,尝试创建引用无论是从Visual Studio中的结果在下面的错误这些端点:

  

有一个错误下载的https://本地主机/ [命名空间] / [服务名称] .SVC /安全。   请求失败,HTTP状态400:错误的请求。   元数据包含引用无法得到解决:将https://本地主机/ [命名空间] / [服务名称] .SVC /安全。   内容类型应用程序/肥皂+ XML;字符集= UTF-8不支持的服务的https://本地主机/ [命名空间] / [服务名称] .SVC /安全。客户端和服务绑定可能不匹配。   远程服务器返回错误:(415)无法处理邮件,因为内容类型应用程序/肥皂+ XML;字符集= UTF-8是不是预期的类型为text / xml;字符集= UTF-8'..   如果该服务在当前的解决方案定义,尝试构建解决方案,并再次添加服务引用。

添加引用访问http://本地主机/ [命名空间] / [服务名称] .SVC做工不错

解决方案

这一切看起来像它的工作对我来说,你似乎只是为了混淆的服务URL和端点URL的概念:

  • 在没有每个&其中只有一个服务的URL;服务>每个协议元素。这是用来获取测试页,添加一个服务引用,并获取WSDL文档(通过?WSDL 查询参数)。
  • 还有每个&其中一个端点的URL;端点> 元素。这是那些在 /基本 /安全结束。的的只有的事情,这些URL会做的是接受SOAP请求。你不能从元数据,他们或浏览到他们。有一个例外,你可以使用暴露 / MEX 端点 mexHttpBinding mexHttpsBinding ,它通过一个SOAP请求返回的元数据。这完全是可选的,你的情况是不必要的,因为你是暴露通过HTTP(S)的WSDL GET来代替。

在客户端,在Visual Studio中,添加服务引用使用的http://本地主机/ [命名空间] / [服务] .SVC 。如果手动定义客户端的端点,可以设置自己的地址,的http://本地主机/ [命名空间] / [服务] .SVC /基本 HTTP: //本地主机/ [命名空间] / [服务] .SVC /安全分别。

更新:

要prevent的的http://本地主机/ [命名空间]从响应请求/ [服务] .SVC 网​​址,禁止元数据发布在服务配置

 <行为>
    < serviceBehaviors>
        <行为名=[命名空间] [ServiceNameBehavior]。>
            < serviceMetadata httpGetEnabled =假httpsGetEnabled =FALSE/>
            < serviceDebug includeExceptionDetailInFaults =真/>
        < /行为>
    < / serviceBehaviors>
< /行为>
 

显然,如果你这样做,那么你可以不再添加任何客户端code新服务的参考,但毕竟是在生产环境中,你控制客户端和服务器code完全可以接受的。

I created a WCF web service and hosted it on IIS. The web.config looks something like this:

[...]
<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="[Namespace].[ServiceNameBehavior]">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>

    <services>
        <service name="[Namespace].[ServiceName]" behaviorConfiguration="[NameSpace].[ServiceNameBehavior]" >
            <endpoint address="basic" binding="basicHttpBinding" contract="[Namespace].[IService]" />
            <endpoint address="secure" binding="basicHttpsBinding" contract="[Namespace].[IService]" />
        </service>
    </services>
</system.serviceModel>
[...]

When I access http://localhost/[Namespace]/[ServiceName].svc I get the usual web service web page indicating you have created a service, and that to test it you should call the service using svcutil.exe, etc, etc...

Now.. the problem is that, as defined in the web.config, I want to use two types of connections for this web service (and actually just limit the access to those two, so disabling the default .svc call) but when I go to http://localhost/[Namespace]/[ServiceName].svc/basic or https://localhost/[Namespace]/[ServiceName].svc/secure I get a blank page nor can I access the services from a local-hosted PHP page.

Is it normal that these bindings behave like this? If not, How can I fix it?


Update 1


I also noticed that trying to create references to either of these endpoints from Visual Studio results in the following error:

There was an error downloading 'https://localhost/[Namespace]/[ServiceName].svc/secure'. The request failed with HTTP status 400: Bad Request. Metadata contains a reference that cannot be resolved: 'https://localhost/[Namespace]/[ServiceName].svc/secure'. Content Type application/soap+xml; charset=utf-8 was not supported by service https://localhost/[Namespace]/[ServiceName].svc/secure. The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'.. If the service is defined in the current solution, try building the solution and adding the service reference again.

Adding a reference to http://localhost/[Namespace]/[ServiceName].svc works good.

解决方案

It all looks like it's working to me, you just seem to have confused the concepts of Service URL and Endpoint URL:

  • There is only one service URL per <service> element per protocol. This is used to get the test page, to add a service reference, and to get the WSDL document (via the ?wsdl query parameter).
  • There is also one endpoint URL per <endpoint> element. These are the ones ending in /basic or /secure. The only thing that these URLs will do is accept SOAP requests. You can't get metadata from them or browse to them. There is one exception to this, you can expose a /mex endpoint using a mexHttpBinding or mexHttpsBinding which returns metadata via a SOAP request. This is entirely optional, and in your case is unnecessary, since you are exposing the WSDL via HTTP(S) GET instead.

On the client side, in Visual Studio, you Add Service Reference using http://localhost/[Namespace]/[Service].svc. If defining client endpoints manually, you set their addresses to http://localhost/[Namespace]/[Service].svc/basic and http://localhost/[Namespace]/[Service].svc/secure respectively.

UPDATE:

To prevent the http://localhost/[Namespace]/[Service].svc URL from responding to requests, disable metadata publishing in the service config:

<behaviors>
    <serviceBehaviors>
        <behavior name="[Namespace].[ServiceNameBehavior]">
            <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

Obviously if you do this then you can no longer add a new service reference in any client code, but that is perfectly acceptable in a production environment where you control both client and server code.

这篇关于空响应对WCF Web服务与终端自定义地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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