如何使用IIS上托管的wsHttpBinding配置WCF服务并通过Web消耗它? [英] How to configure WCF Service with wsHttpBinding hosted on IIS and consumable over Web?

查看:94
本文介绍了如何使用IIS上托管的wsHttpBinding配置WCF服务并通过Web消耗它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,我对WCF服务没有任何经验(这是我第一次尝试创建,配置和使用WCF服务).

I'm not experienced with WCF Service in general (this is my 1'st attempt to create, configure and consume WCF Service).

  1. 我已经创建了WCF服务,并通过WCF测试客户端(在Visual Studio中开发PC上")对其进行了测试,一切正常.
  2. 我已将其托管在我们服务器(不是开发PC)上的IIS中,并将其添加到ASP.Net v4.0应用程序池中,并使用Windows Forms Application(来自开发PC)对其进行了测试,在其中添加了服务参考"托管了WCF服务,一切正常.
  3. 我已经从家用PC上尝试了相同的应用程序(和application.config),但出现此错误:服务未验证呼叫者".

我曾尝试过谷歌搜索",大多数人说该错误是由位于不同域上的计算机引起的(这是可以预期的,因为我的家用PC和工作中的服务器甚至不在同一网络上),但是我认为这是错误的WCF可通过Web消耗,还是我猜错了?

I've tried to "Google it" and most said that error is caused by computers on different Domain (which is expected because my Home PC and Server at Work aren't even on the same network), but I presume that WCF is consumable over Web or am I presuming wrong?

On Development PC, WCF Service address is redirected to Local IP of Server PC. I've also added REST/Web Service because I need to POST some data and it's consumable without any problems.

有什么我想念的吗?

Web.config:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>

  <system.serviceModel>

    <services>
        <service name="TestWCF.TestServis">
            <endpoint address="TestWCF" binding="wsHttpBinding" contract="TestWCF.ITestServis" />
        </service>

        <service name="TestWCF.TestPushingServis">
            <endpoint address="" binding="webHttpBinding" contract="TestWCF.ITestPushingServis" behaviorConfiguration="web" />
        </service>
    </services>

    <behaviors>

      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>     
      </serviceBehaviors>

      <endpointBehaviors>
        <behavior name="web">
            <webHttp />
        </behavior>
      </endpointBehaviors>

    </behaviors>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

Application.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_ITestServis"
                         maxReceivedMessageSize="2147483647" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://testdomain.com:12345/TestServis.svc/TestWCF"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITestServis"
                contract="TestServisReference.ITestServis"
                name="WSHttpBinding_ITestServis">
                <identity>
                    <servicePrincipalName value="host/ServerName" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

推荐答案

对于wsHttpBinding,您可能需要使用ClientCredentials属性设置Windows凭据(用户名,密码和Windows域).

For wsHttpBinding you may need to set your windows credentials (username, password and windows domain) using ClientCredentials property.

yourClient.ClientCredentials.Windows.ClientCredential.UserName = "name"
yourClient.ClientCredentials.Windows.ClientCredential.Password = "password"
yourClient.ClientCredentials.Windows.ClientCredential.Domain = "domain"

也-您可以尝试在绑定中将安全模式设置为无:

Also - you may try to set security mode to none in your binding:

<security mode="None" />

希望有帮助,

毛巾

这篇关于如何使用IIS上托管的wsHttpBinding配置WCF服务并通过Web消耗它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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