How to configure WCF Service with wsHttpBinding hosted on IIS and consumable over Web?

这一生的挚爱 提交于 2019-12-25 01:07:41

问题


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

  1. I've created my WCF Service, tested it through WCF Test Client (on Development PC "in" Visual Studio) and everything was working.
  2. I've hosted it in IIS on our Server (not Development PC) adding it to ASP.Net v4.0 Application Pool, tested it with Windows Forms Application (from Development PC) in which I've added Service Reference to hosted WCF Service and everything was working.
  3. I've tried same application (and application.config) from my Home PC and I'm getting this error: "The caller was not authenticated by the service".

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.

Is there something I'm missing?

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>

回答1:


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

Hope it helps,

Pawel



来源:https://stackoverflow.com/questions/30161966/how-to-configure-wcf-service-with-wshttpbinding-hosted-on-iis-and-consumable-ove

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!