无法使用应用程序连接到WCF服务,但可以使用SOAPUI

时间:2018-01-15 17:02:24

标签: vb.net wcf credentials

我尝试使用托管在共享服务器中的WCF服务。它与SOAPUI完美配合,但当我尝试使用我的vb.net应用程序时,它会给我这个错误:

  

http请求未经授权使用客户端身份验证方案   "匿名"

我尝试了很多解决方案,更改了我的应用程序的app.config,添加了security mode="TransportCredentialOnly"clientCredentialType="Windows""NTLM",它只更改了错误的最后部分,给予"谈判"用"匿名"。

这里我如何在app.config中添加安全性

            <security mode="TransportCredentialOnly">
              <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
              <message clientCredentialType="UserName" algorithmSuite="Default" />
            </security>

我认为这是一个应用程序问题,因为正如我之前所说,它在SOAPUI中完美运行,我不知道是否需要添加更多内容。

WCF的web.config:

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

编辑:

我刚收到服务器提供商的回复,他说有一个程序ModSecurity阻止我访问WCF,直到我添加正确的内容标头和用户代理。如何将其添加到通话中?

更新

我使用了GMan80013的答案,现在我已经陷入了这一部分。

我收到此错误&#34; Coul未加载类型&#39; Microsoft.ServiceModel.Dispatcher.HttpUserAgentBehaviorExtensionElement,SolutionPruebas.ServiceModel,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089&#39 ;注册了分机&#39; httpUserAgent&#39;&#34;。

这个错误来自这部分,我假设:

<behaviorExtensions>

  <add name="httpUserAgent" type="Microsoft.ServiceModel.Dispatcher.HttpUserAgentBehaviorExtensionElement, SolutionPruebas.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

</behaviorExtensions>

或者从这里开始。

    <behaviors>

<endpointBehaviors>

  <behavior name="LegacyServiceEndpointBehavior">

    <httpUserAgent userAgent="test user agent" />

  </behavior>

</endpointBehaviors>

0 个答案:

没有答案