【发布时间】:2013-09-07 01:38:48
【问题描述】:
我承认我已经挣扎了几个小时。我的 Silverlight 应用程序和 WCF Web 服务之间的绑定/配置一定是缺少某些东西。它工作了一段时间,但我一定是不小心更改了一些设置,我无法再让它工作了。
在 Visual Studio 中,当我同时启动 Service 和 Silverlight 应用程序时,我在 web.config 文件中禁用了 Windows 身份验证以进行调试。部署时,我返回并更改我的配置文件以启用 Windows 安全/传输,以便我可以在 Web 服务端获取用户凭据。
现在,当我使用 IIS 将 WCF 服务和 Silverlight 应用程序部署到另一台计算机时,当 Silverlight 尝试联系 WCF 服务时,我收到“未找到”错误。有人可以向我解释存在的不同配置文件以及每个配置文件应该指向什么吗?这是我在各自位置的配置文件:
wwwroot\webserviceapp\web.config
<?xml version="1.0" encoding="UTF-8"?>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpointBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="WebserviceName.Service1">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="BasicHttpEndpointBinding"
name="BasicHttpEndpoint" contract="WebserviceName.IService1">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
wwwroot\web.config - 我猜这是 silverlight 的 web.config?
<?xml version="1.0" encoding="UTF-8"?>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpoint" 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" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://<<<ip_to_machine>>>/webserviceapp/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpEndpoint"
contract="ServiceReference1.IService1"
name="BasicHttpEndpoint" />
</client>
</system.serviceModel>
<system.webServer>
<defaultDocument>
<files>
<add value="ProjectTestPage.html" />
</files>
</defaultDocument>
</system.webServer>
wwwwroot\ClientBin\SilverlightApp.xap(ServiceReferences.ClientConfig 文件):
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpoint" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportCredentialOnly" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://<<<ip_to_machine>>>/webserviceapp/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpEndpoint"
contract="ServiceReference1.IService1"
name="BasicHttpEndpoint" />
</client>
</system.serviceModel>
这三个配置文件似乎可以驱动一切,除非我错了?由于我在一个环境中开发并部署到另一个环境,因此我似乎必须更改这些文件以指向正确的资源。当我在将 Silverlight 应用程序部署到新机器后点击它时,我会加载应用程序。完成加载后,它发出的第一个 Web 服务调用失败并出现异常,我在 Chrome 控制台中得到了这个:
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://<<<ip_to_machine>>>/webserviceapp/Service1.svc
Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://<<<ip_to_machine>>>/webserviceapp/Service1.svc
Uncaught Error: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at Project.ServiceReference1.GetAllNewsCompletedEventArgs.get_Result()
at Project.View.Home1.ClientGetAllNewsCompleted(Object pSender, GetAllNewsCompletedEventArgs pEventArgs)
at Project.ServiceReference1.Service1Client.OnGetAllNewsCompleted(Object state)
我 99% 确定该服务永远不会受到攻击。我在被调用的函数的最顶部有一个日志语句,它从不记录任何内容。
IIS 配置: 网络服务认证: 匿名 = 已禁用 ASP.NET 模拟 = 已禁用 Windows 身份验证 = 已启用
默认网站(我的 silverlight 应用程序所在的位置): 匿名 = 已禁用 ASP.NET 模拟 = 已禁用 Windows 身份验证 = 已启用
任何人有任何建议,或者需要我的更多信息来帮助调试?
编辑:值得注意的是,我能够从另一台机器导航到服务,并且可以很好地查看服务 wsdl。例如:
http://ipaddress/webserviceapp/Service1.svc
我可以看到这个很好,没有错误。
【问题讨论】:
-
我没有阅读所有这些,但是您是否考虑过使用跟踪日志记录或使用 Fiddler 来获取更多详细信息?见inaspiralarray.blogspot.com/2013/04/… 和inaspiralarray.blogspot.com/2013/03/…。
-
我已返回并在所有 web.config 文件中启用了跟踪日志记录,但从未生成任何日志文件。知道为什么会这样吗?
-
您的跟踪日志设置有问题,或者您的服务永远不会受到影响。你试过 Fiddler 吗?
-
好吧,你强迫我使用 Fiddler,它告诉我我的确切错误!非常感谢。
标签: c# asp.net .net wcf silverlight