C# 没有通道可以接受带有操作的消息';http://schemas.xmlsoap.org/ws/2004/09/transfer/Get
下面是我的服务代码C# 没有通道可以接受带有操作的消息';http://schemas.xmlsoap.org/ws/2004/09/transfer/Get,c#,wcf,C#,Wcf,下面是我的服务代码 using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; using System.ServiceModel.Channels; using System.Xml; names
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.ServiceModel.Channels;
using System.Xml;
namespace WcfServiceRaw
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public Message GetData()
{
// Create body
string body = ("<test>data</test>");
// Create messatge
MessageVersion ver = OperationContext.Current.IncomingMessageVersion;
Message msg = Message.CreateMessage(ver, "ResponseToGetDataRequest", body);
//Debug.WriteLine(msg.ToString());
return msg;
}
}
class TestDataWriter : BodyWriter
{
string _data;
public TestDataWriter(string data)
: base(false)
{
_data = data;
}
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
{
writer.WriteRaw(_data);
}
}
}
最后我遇到了我的we配置代码
<?xml version="1.0"?>
<configuration>
<system.diagnostics>
<trace autoflush="true"></trace>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource" switchValue="Information, ActivityTracing">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\logs\TracesBinding.svclog" />
</sharedListeners>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<!-- <system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>-->
<system.serviceModel>
<services>
<service name="WcfServiceRaw.Service1" behaviorConfiguration="MyServiceTypeBehaviors" >
<!-- Service Endpoints -->
<endpoint
address="http://localhost:49389/Service1.svc" binding="wsHttpBinding" contract="WcfServiceRaw.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
客户端代码如下所示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Channels;
using System.Xml;
namespace WcfClientRaw
{
class Program
{
static void Main(string[] args)
{
//IMyContract proxy = ChannelFactory<IMyContract>.CreateChannel(new BasicHttpBinding(), new EndpointAddress(address));
WcfServiceRaw.Service1Client proxy = new WcfServiceRaw.Service1Client();
using (proxy as IDisposable)
{
Message msg = proxy.GetData();
Console.WriteLine(msg.ToString());
Console.WriteLine();
XmlDictionaryReader xdr = msg.GetReaderAtBodyContents();
//string exp = "<test>data</test>";
string act = xdr.ReadOuterXml();
//Debug.Assert(exp == act);
Console.WriteLine(act);
Console.ReadLine();
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.ServiceModel.Channel;
使用System.Xml;
命名空间WcfClientRaw
{
班级计划
{
静态void Main(字符串[]参数)
{
//IMyContract proxy=ChannelFactory.CreateChannel(新的BasicHttpBinding(),新的EndpointAddress(address));
WcfServiceRaw.Service1Client proxy=新的WcfServiceRaw.Service1Client();
使用(代理作为IDisposable)
{
Message msg=proxy.GetData();
Console.WriteLine(msg.ToString());
Console.WriteLine();
XmlDictionaryReader xdr=msg.GetReaderAtBodyContents();
//string exp=“数据”;
string act=xdr.ReadOuterXml();
//Assert(exp==act);
控制台。写入线(act);
Console.ReadLine();
}
}
}
}
应用程序配置是
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49389/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceRaw.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>-->
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49389/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="WcfServiceRaw.IService1"
name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="sheraz.akbar@curemd.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
现在我遇到了上述异常,您能帮我解决吗?跟踪日志也显示没有消息通信。该错误似乎更多地与尝试使用mex而不是wsdl导入元数据有关。您从何处获得此错误-在客户端或服务器日志上?你即将发布的soap是什么样子的?Yaron Naveh thnaks回答我没有找到我从哪里得到这个错误你可以在webservice web.config中看到跟踪日志我粘贴了所有的代码你可以测试它并给我一个解决方法吗。感谢如果这是跟踪日志中的错误,则很可能与此无关-它是在添加服务引用时出现的。检查日志中是否有任何其他错误。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49389/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServiceRaw.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>-->
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49389/Service1.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="WcfServiceRaw.IService1"
name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="sheraz.akbar@curemd.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>