views:

385

answers:

3

Im trying to consume a Service with an WCF Console Application. But the only thing i get as a Response is "The remote server returned an unexpected response: (400) Bad Request."

The Service is configurated with the following options:

<services>
  <service name="TryOut.BasicService" behaviorConfiguration="NicksBasicBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://192.168.10.67:8000/Service" />
      </baseAddresses>
    </host>

    <endpoint address ="http://192.168.10.67:8000/Service"

              name="NicksEndpoint"
              binding="basicHttpBinding"
              contract="TryOut.IBasicService"
              bindingConfiguration="BasicBinding"
              />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="NicksBasicBehavior">       
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

<binding name="BasicBinding">
    <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"/>
    </security>
</binding>

The configuration file of my Client is the following:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="NicksEndpoint" closeTimeout="00:01:00" openTimeout="00:01:00"
        receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://192.168.10.67:8000/Service" binding="basicHttpBinding"
      bindingConfiguration="NicksEndpoint" contract="ServiceReference1.IBasicService"
      name="NicksEndpoint" />
</client>

Now everything works fine when im starting the client on the same pc as the service. But if im try to running the Client on a machine which is not in the domain of the server pc then i get an error, although i provide the Login informations in the client code

c.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("Nick", "password", "mydomain");

Does anybody got an idea what im doing wrong and how can i fix it? Thanking you in anticipation!

Cheerz Nick

A: 

According to this article on MSDN, it looks as if you need to specify your credentials differently:

WCFTestService.Service myService = new WCFTestService.Service();
myService.Credentials = System.Net.CredentialCache.DefaultCredentials;
MessageBox.Show(myService.GetData(123, true));
myService.Dispose();

Could you try to use this code and try to pass the Windows credentials into myService.Credentials ? Does that work?

Marc

marc_s
A: 

have you tried specifing the userPrincipalName in the identity element on your clients endpoint?

A: 

Hi Marc thanks for the tipp, i followed the tutorial and build the application. Its no problem to access the service when the client running on the same pc as the server. But my i want that the client application running on a pc outside the server domain. When i try to arrange this with the Credentials property the i get the "(502) Cannot connect Error". So this unforunately doesnt work.

i tried to privide the prinicple name in the endpoints identity

<endpoint address="http://192.168.10.67:8000/Service" binding="basicHttpBinding"
    bindingConfiguration="NicksEndpoint" contract="ServiceReference1.IBasicService"
    name="NicksEndpoint"  >
    <identity>
      <userPrincipalName value="Nick"/>
    </identity>
  </endpoint>

but i still get the same error "Bad Request".

Cheers Nick