我一直在与IIS争夺一个星期以使这个网络服务运行,并且它一直在反击并试图让我退出我的工作(感谢上帝我的工作不涉及IIS的大部分)。我创建了一个WCF服务和一个与之交谈的客户端。在我的本地系统上运行时,他们彼此相爱;没有任何错误。然而,当我在IIS上托管服务时,故事就会转变......
我认为,我已将服务作为网页加载。我一直在学习多个教程,但没有一个能够直接回答如何安装Web服务。我所做的是使用Visual Studio中的Publish功能在我的桌面上发布服务(使用“to file”选项或其他任何名称)。然后我将该文件夹移动到IIS服务器并将其放在wwwroot文件夹中。之后,我尝试使用该文件夹创建一个新的网页。它包含.svc文件,web.config文件和包含.dll的\ bin目录。
配置端点后(我知道它们配置正确,因为错误消息从“找不到端点1”变为此),运行客户端程序将导致每次都出现405错误。我为要转储的异常创建了一个日志,这里是:
12/20/2013 12:44:19 PM - System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (405) Method Not Allowed. ---> System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at TestWebClient.TestWebService.ITestService.Repeat(String input)
at TestWebClient.TestWebService.TestServiceClient.Repeat(String input) in c:\Users\x\Documents\Visual Studio 2012\Projects\TestWebClient\TestWebClient\Service References\TestWebService\Reference.cs:line 56
at TestWebClient.Program.Repeat() in c:\Users\xl\Documents\Visual Studio 2012\Projects\TestWebClient\TestWebClient\Program.cs:line 55
at TestWebClient.Program.Main(String[] args) in c:\Users\x\Documents\Visual Studio 2012\Projects\TestWebClient\TestWebClient\Program.cs:line 16
如果有任何其他信息有用,请告诉我们。我已经尝试了405个错误的多个解决方案,我没有在哪里。虽然我参加了一些关于IIS的在线课程,但我仍然是一个初学者。无论如何,如果有人有任何想法,请告诉我。
编辑: 这是web.config,其中包含Lex Li要求添加的代码。另外,我无法在本地系统和服务器系统上找到svctraceviewer.exe。我现在正在寻找解决方案。
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
>
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "C:\temp\WCFDiagnosticsExample.svclog" />
</sharedListeners>
</system.diagnostics>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="TestWebService.TestService">
<endpoint address="http://www.wsp41.com/" binding="basicHttpBinding"
bindingConfiguration="" contract="TestWebService.ITestService" />
</service>
</services>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000"
/>
</diagnostics>
</system.serviceModel>
</configuration>
答案 0 :(得分:0)
我相信这个问题有两种可能性:
“运行”输入:“%WINDIR%\ Microsoft.Net \ Framework \ v3.0 \ Windows Communication Foundation \ ServiceModelReg.exe”-r
或者
打开admin cmd提示符,并在c:\ Windows \ Microsoft.NET \ Framework \ v3.0 \ Windows Communication Foundation文件夹中执行ServiceModelreg -i。
您可以找到有关此here的其他帮助,以确认WCF是否已在服务器中正确安装:
2 - 问题客户端
根据您正在构建的应用程序类型,您可能需要启用跨域调用:crossDomainScriptAccessEnabled="true"
http://msdn.microsoft.com/en-us/library/ee834511(v=vs.110).aspx