使用本地安装localhost:1179 / Service1.svc时没有任何错误。但是当我使用ofiwcf.kocgokhan.com/Service1.svc时,我遇到以下错误:
消息:
接收HTTP响应时发生错误 http://ofiwcf.kocgokhan.com/Service1.svc。这可能是由于 服务端点绑定不使用HTTP协议。这也可以 是由于服务器中止了HTTP请求上下文 (可能由于服务关闭)。请参阅服务器日志了解更多 的信息。
的InnerException:
{System.ServiceModel.CommunicationException:发生错误 接收HTTP响应 http://ofiwcf.kocgokhan.com/Service1.svc。这可能是由于 服务端点绑定不使用HTTP协议。这也可以 是由于服务器中止了HTTP请求上下文 (可能由于服务关闭)。请参阅服务器日志了解更多 细节。 ---> System.Net.WebException:底层连接是 已关闭:接收时发生意外错误。 ---> System.IO.IOException:无法从传输中读取数据 连接:远程强制关闭现有连接 主办。 ---> System.Net.Sockets.SocketException:现有连接 被远程主机强行关闭了 System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) ---内部异常堆栈跟踪结束---在System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)at System.Net.PooledStream.EndRead(IAsyncResult asyncResult)at System.Net.Connection.ReadCallback(IAsyncResult asyncResult) ---内部异常堆栈跟踪结束---在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult的 结果) ---内部异常堆栈跟踪结束---
服务器堆栈跟踪:at System.Runtime.AsyncResult.End [TAsyncResult](IAsyncResult结果)at at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult 在System.ServiceModel.Channels.ServiceChannel.EndCall(String。) action,Object [] outs,IAsyncResult result)at System.ServiceModel.Channels.ServiceChannelProxy.InvokeEndService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天 消息)
在[0]处重新抛出异常:at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天 reqMsg,IMessage retMsg)at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; msgData,Int32类型)at WinFormWCFTest.ServiceTest.IService1.EndTopla(IAsyncResult结果)at at WinFormWCFTest.ServiceTest.Service1Client.EndTopla(IAsyncResult的 结果)在c:\ users \ bygokhankoc \ documents \ visual studio中 2010 \项目\ testWCF \ WinFormWCFTest \服务 参考文献\ ServiceTest \ Reference.cs:第162行 WinFormWCFTest.ServiceTest.Service1Client.OnEndTopla(IAsyncResult的 结果)在c:\ users \ bygokhankoc \ documents \ visual studio中 2010 \项目\ testWCF \ WinFormWCFTest \服务 参考文献\ ServiceTest \ Reference.cs:第172行 System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult的 结果)}
服务器配置:
<system.web>`enter code here`
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength ="2147483647" executionTimeout="103600"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<!-- 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="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
客户端app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://ofiwcf.kocgokhan.com/Service1.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceTest.IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
赢取应用。代码:
Service1Client proxy = new Service1Client();
private void button1_Click(object sender, EventArgs e)
{
proxy.ToplaAsync(5, 2);
proxy.ToplaCompleted += new EventHandler<ToplaCompletedEventArgs>(proxy_ToplaCompleted);
}
void proxy_ToplaCompleted(object sender, ToplaCompletedEventArgs e)
{
var rs = e.Result;
MessageBox.Show(rs.ToString());
proxy.Close();
}
WCF代码: IService1 =&gt;
[ServiceContract]
public interface IService1
{
[OperationContract]
int Topla(int value1,int valu2);
[OperationContract]
int Cikart(int value1, int valu2);
[OperationContract]
List<string> Isimler(params string[] isim);
// TODO: Add your service operations here
}
Service1.svc
public int Topla(int value1, int valu2)
{
return value1 + valu2;
}
public int Cikart(int value1, int valu2)
{
return value1 + valu2;
}
public List<string> Isimler(params string[] isim)
{
List<string> rs = new List<string>();
foreach (var item in isim)
{
rs.Add(item);
}
return rs;
}