0

我一直在努力解决这个问题,阅读了很多问题,文章但无法解决。所以我在这里。

Webservice 在网站内,我从控制台应用程序 [测试] 访问它。这是我的 Web.Config 代码

 <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Services.CilsDataReceiveBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="WindowsAuth">
          <security mode="TransportCredentialOnly" >
            <transport clientCredentialType="Windows"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Services.CilsDataReceiveBehavior" name="Services.CilsDataReceive">
        <endpoint address="" binding="basicHttpBinding" name="BasicHttpEndpoint" bindingConfiguration="WindowsAuth" contract="Services.ICilsDataReceive" />
        <endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
      </system.serviceModel>

下面是我在控制台应用程序中使用的代码和 app.config 。

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_ICilsDataReceive" 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="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://wgb01wa7002.worldwide.co.uk:44001/Services/CilsDataReceive.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICilsDataReceive"
                contract="ICilsDataReceive" name="BasicHttpBinding_ICilsDataReceive" />
        </client>
    </system.serviceModel>

下面是cs代码

icDateList.titlesField = titles.ToArray();
            var cilsDataReceiveClient = new CilsDataReceiveClient();
            try
            {
                cilsDataReceiveClient.RecieveICDateList(icDateList);
                Console.WriteLine(" O_O   Service saved the data   O_O");
            }
            catch (Exception exception)
            {
                cilsDataReceiveClient.Abort();
                Console.WriteLine(exception.Message);
                throw;
            }

            finally
            {
                Console.Read();

            }

错误消息是“HTTP 请求未经授权,客户端身份验证方案‘匿名’。从服务器收到的身份验证标头是‘协商,NTLM’。”

如果将我的控制台应用程序 app.config 更改为

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

我收到以下错误“'http://wgb01wa7002.worldwide.co.uk:44001/Services/CilsDataReceive.svc' 无法激活。有关更多信息,请参阅服务器的诊断跟踪日志。”

我尝试了很多尝试 WsHttpBinding 但我认为使用 Https 而不是 http。

你能建议点什么吗?

编辑:如果我从浏览器访问它,我会得到“此服务的安全设置需要'匿名'身份验证,但托管此服务的 IIS 应用程序未启用它。”

编辑 2:我尝试使用 netTCPBinding 并更改错误“提供的 URI 方案 'http' 无效;预期为 'https'。看来我不应该使用它。参数名称:通过”

编辑 3:我尝试使用 wsHttpBinding,但仍然出现错误。它就像永无止境的错误。

4

1 回答 1

0

首先,您的桌面环境是否设置为测试 ssl?如果没有,请添加它。

其次,您可能缺少 WsHttpsBinding

于 2012-07-19T00:22:21.933 回答