【问题标题】:Silverlight 4 application connecting to WCF Service failsSilverlight 4 应用程序连接到 WCF 服务失败
【发布时间】:2011-05-08 13:20:19
【问题描述】:

一直在研究连接到我们服务器上的 WCF 服务的 Silverlight 应用程序。我正在使用 .NET 4.0 进行开发。在本地一切正常,但我尝试在我们的服务器上部署 WCF 服务,但它不起作用。

服务运行良好,我通过在浏览器中输入 URL 进行了检查。但是每当我从我的 Silverlight 应用程序中拨打电话时,它都会失败并出现错误:

System.ServiceModel.CommunicationException:远程服务器返回错误:NotFound。

我的 Web.Config 文件在下面给出了详细的错误。我使用 fiddler 检查消息,我可以看到来自服务器的响应包含文本。

a:身份验证失败。访问被拒绝。

我能做些什么来解决这个问题?问题是我的托管服务器不允许在 IIS 中打开 Windows 身份验证。找不到该设置。我正在使用 Godaddy Windows 托管。

任何指针?

Web.Config:

    <authentication mode="Windows"/>
<customErrors mode="Off"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"></serviceHostingEnvironment>    
<services>
  <service name="WarpArtOnline.Service1" behaviorConfiguration="WarpArtOnline.Service1Behavior">
    <endpoint binding="basicHttpBinding" bindingConfiguration="MaxSizeBinding" contract="WarpArtOnline.IService1">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
  </service>
</services>

<bindings>
  <basicHttpBinding>
    <binding name="MaxSizeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <!--<transport clientCredentialType="Windows"/>-->
        <!--<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />-->
      </security>
    </binding>
  </basicHttpBinding>
</bindings>


    <behaviors>
        <serviceBehaviors>
            <behavior name="WarpArtOnline.Service1Behavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

错误: {System.ServiceModel.CommunicationException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClass5.b_4(Object sendState) at System.Net.Browser.AsyncHelper.<>c_DisplayClass4.b_1(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result) --- End of inner exception stack trace --- at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result) at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result) at System.ServiceModel.ClientBase1.ChannelBase1.EndInvoke(String methodName, Object[] args, IAsyncResult result) at ImagingSL.WebWarp.Service1Client.Service1ClientChannel.EndwarpImage(IAsyncResult result) at ImagingSL.WebWarp.Service1Client.ImagingSL.WebWarp.IService1.EndwarpImage(IAsyncResult result) at ImagingSL.WebWarp.Service1Client.OnEndwarpImage(IAsyncResult result) at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)}

【问题讨论】:

  • 嗯,通过 Internet 使用 Windows 身份验证。什么样的用户应该使用该服务?
  • 任何人都应该可以访问该服务。

标签: c# .net silverlight wcf


【解决方案1】:

您是否在 Silverlight 项目中使用 ServiceReferences.ClientConfig 文件?如果是,您是否检查了所有端点设置?

【讨论】:

  • 问题是特定错误“NotFound”可能意味着任何事情。这只是 WCF 用来表示失败的一般错误消息。您是否尝试过启用 WCF 跟踪 (msdn.microsoft.com/en-us/library/ms730064.aspx)。它可能会为您提供更多线索。
  • P.S 你知道 WCF 服务是如何在 IIS 上配置的吗?他们是否设置为匿名访问?
  • 刚刚注意到您的 web.config 中仍有 authenticationMode=Windows。如果每个人都可以访问服务,则需要将其更改为 authenticationMode=None。
  • 大家好,问题是 Web 服务器上的 wcf 服务运行在中等信任级别的环境中。我的 WCF 服务包含需要完全信任的代码。我联系了支持人员,但由于我在共享主机上,他们无法帮助我。
【解决方案2】:

您是否修改了 clientaccesspolicy.xml 文件?您需要在此文件中启用跨域访问。参考此 Making a Service Available Across Domain Boundaries

【讨论】:

  • 他的帖子中没有任何内容表明存在跨域问题。
  • 我的域根目录中有一个 clientaccesspolicy.xml,这不是问题。
猜你喜欢
  • 2014-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多