I'm trying to consume a WCF service, hosted in a shared server. it works perfectly with SOAPUI, but when i tried to do it with my vb.net application it give me this error:
the http request is unauthorised with client authentication scheme "anonymous".
I tried a lot of solutions, changing the app.config of my application, adding security mode="TransportCredentialOnly"
, with clientCredentialType="Windows"
and "NTLM"
, and it only changes the last part of the error, giving "Negotiate" with "anonymous".
here how i add security in app.config
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
I think this is an application problem because, as I said before, it works perfectly in SOAPUI, I don't know if I need to add something more.
The web.config of WCF:
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength ="262144" executionTimeout="103600"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="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>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<httpErrors errorMode="Detailed"/>
</system.webServer>
EDIT:
I just receive an answer from server's provider and he said that there's a program, ModSecurity, that is blocking me access to WCF until i add a correct content header and user agent. How can i add it to the call?
UPDATE:
I used the answer of GMan80013 and now i'm stuck in this part.
I'm getting this error "Coul not load type 'Microsoft.ServiceModel.Dispatcher.HttpUserAgentBehaviorExtensionElement, SolutionPruebas.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' registered for the extension 'httpUserAgent'".
This error come from this part, I assume:
<behaviorExtensions>
<add name="httpUserAgent" type="Microsoft.ServiceModel.Dispatcher.HttpUserAgentBehaviorExtensionElement, SolutionPruebas.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</behaviorExtensions>
Or from here.
<behaviors>
<endpointBehaviors>
<behavior name="LegacyServiceEndpointBehavior">
<httpUserAgent userAgent="test user agent" />
</behavior>
</endpointBehaviors>