0

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>
Djiber
  • 55
  • 1
  • 9

1 Answers1

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

Pawel Wrobel
  • 494
  • 3
  • 13
  • I've tried adding: ` ` and: `bindingConfiguration="wsHttpBinding" ` to "endpoint" But then I'm getting: Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. – Djiber May 11 '15 at 14:15
  • Also I guess You've ment: client.ClientCredentials.UserName.UserName = "username"; client.ClientCredentials.UserName.Password = "password"; My Client doesn't have client.ClientCredentials.Domain nor client.ClientCredentials.UserName.Domain. But I didn't notice that it's checking provided credentials because I've entered some random information and it passed on my Development PC, but same error occures on my Home PC. – Djiber May 11 '15 at 14:26
  • 1
    Sorry, I mistyped my answer. I meant: ClientCredentials.Windows.ClientCredential.UserName. I will edit my answer. – Pawel Wrobel May 11 '15 at 14:41
  • It seems that it's working (I've tried to set it up on my Home PC and Test it from Server and Development PC because I don't have rights to manage accounts at work and now I'm getting different error, but it seems Authentication passed). I need to wait for our administration to approve user so I can test it. Thank You for all Your time, help, informations and patience. – Djiber May 12 '15 at 14:25