Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 发送到';的消息';由于EndpointDispatcher上的AddressFilter不匹配,无法在接收器上处理_C#_Wcf_Rest - Fatal编程技术网

C# 发送到';的消息';由于EndpointDispatcher上的AddressFilter不匹配,无法在接收器上处理

C# 发送到';的消息';由于EndpointDispatcher上的AddressFilter不匹配,无法在接收器上处理,c#,wcf,rest,C#,Wcf,Rest,我试图在不修改App.config文件的情况下实现WCF Rest服务 我的服务界面如下所示: [ServiceContract] public interface IService { [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json,

我试图在不修改App.config文件的情况下实现WCF Rest服务

我的服务界面如下所示:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(Method = "POST",
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "/teststr/?string={aStr}")]
    string TestString(string aStr);
}
服务实现非常基本:

public class TestService : IService
{
    public string TestString(string aStr = null)
    {
        Console.WriteLine("The Test() method was called at {0}"
            + "\n\rThe given string was {1}\n\r"
            , DateTime.Now.ToString("H:mm:ss")
            , aStr);

        return aStr;
    }
}
我的主程序运行所有程序:

// Step 1 Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://localhost:8000/ServiceSample/");

// Step 2 Create a ServiceHost instance
ServiceHost selfHost = new ServiceHost(typeof(TestService), baseAddress);

try
{
    // Step 3 Add a service endpoint.
    selfHost.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), 
        "TestService");

    // Step 4 Enable metadata exchange.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    selfHost.Description.Behaviors.Add(smb);

    // Step 5 Start the service.
    selfHost.Open();
    Console.WriteLine("The service is ready.");
    Console.WriteLine("Press <ENTER> to terminate service.");
    Console.ReadLine();

    // Close the ServiceHostBase to shutdown the service.
    selfHost.Close();
}
catch (CommunicationException ce)
{
    Console.WriteLine("An exception occurred: {0}", ce.Message);
    selfHost.Abort();
}
我得到这个信息:

// The message with To '...' cannot be processed at the receiver, due to an 
// AddressFilter mismatch at the EndpointDispatcher. Check that the sender
// and receiver's EndpointAddresses agree.
其他人说,我看过类似的SO问题(但
步骤4
是否已经这样做了?)。这些都不起作用,我也没有发现相关的问题那么有用


是否需要修改App.config文件?我在这里做错了什么?

我意识到上面的评论中有答案,但我将尝试说明我在试图找到问题的解决方案时学到了什么,因为这是谷歌搜索错误消息的第一个页面

我试图从JavaScript调用第三方SOAP Web服务(我知道这很糟糕),但我遇到了这个问题

我调用的SOAP1.2服务要求我在
中放置一个
:To
SOAP寻址头。在这样做以及添加了我从WSDL获得的
:Action
之后,我获得了金牌

SOAP标头最终看起来是什么样子的:

<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsa:To>(WebService URL)</wsa:To>
    <wsa:Action>(Action from WebService WSDL)</wsa:Action>
</soap:Header>

(Web服务URL)
(来自WebService WSDL的操作)
有用网站:


看起来您正在尝试对SOAP服务进行RESTful调用,但这是行不通的——它们是两种完全不同的web服务。尝试使用而不是
ServiceHost
,看看这是否有帮助。谢谢@Tim这么做!我怎么会错过呢。
<soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <wsa:To>(WebService URL)</wsa:To>
    <wsa:Action>(Action from WebService WSDL)</wsa:Action>
</soap:Header>