首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根(/)目录下的WCF自托管soap-service

根(/)目录下的WCF自托管soap-service
EN

Stack Overflow用户
提问于 2014-02-28 22:15:29
回答 1查看 497关注 0票数 0

我有一个向IP发送SOAP消息的设备(充电器),我将在那里接收状态报告,但它总是在根目录中发送,并且不可更改:http://192.168.1.2/

我做了一个WCF服务自托管,我想要接收这些消息。但是我找不到任何关于url重写或侦听服务名称以外的信息,在我的例子中,它变成了http://192.168.1.2/ocpp15

是否可以以任何方式重写/路由自/到/ocpp15/或从/ocpp15/到/?

在Windows服务中托管

代码语言:javascript
复制
        var smb = new ServiceMetadataBehavior
        {
            HttpGetEnabled = true,
            MetadataExporter = { PolicyVersion = PolicyVersion.Policy12 },
        };
        var serviceDebugBehavior = new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true };

       var baseAddress15 = new Uri(String.Format("http://{0}/, Environment.MachineName));
        var host15 = new ServiceHost(typeof(Ocpp15), baseAddress15);

        host15.Description.Behaviors.Add(smb);
        host15.Description.Behaviors.Remove(typeof(ServiceDebugBehavior));
        host15.Description.Behaviors.Add(serviceDebugBehavior);
        host15.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
        host15.AddServiceEndpoint(typeof(IOcpp15), new WSHttpBinding(SecurityMode.None), "");
        host15.Open();

服务联系人

使用/sc选项从WSDL文件生成

代码语言:javascript
复制
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "urn://Ocpp/Cs/2012/06/", ConfigurationName = "Ocpp15")]
public interface IOcpp15
{
    // CODEGEN: Generating message contract since the wrapper name (authorizeRequest) of message AuthorizeRequest does not match the default value (Authorize)
    [System.ServiceModel.OperationContractAttribute(Action = "/Authorize", ReplyAction = "/AuthorizeResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    AuthorizeResponse Authorize(AuthorizeRequest request);
    and so on.....

服务

代码语言:javascript
复制
public class Ocpp15 : IOcpp15
{
    public AuthorizeResponse Authorize(AuthorizeRequest request)
    {
        return new AuthorizeResponse { idTagInfo = ValidateRequest(request) };
    }
    and so on.....
EN

回答 1

Stack Overflow用户

发布于 2014-03-07 07:06:12

我没有在WCF中找到任何解决方案,除了使用Fiddler的黑客攻击。将fiddler设置为侦听端口80并接受外部请求。在另一个端口上侦听WCF,在我的例子中是8081。

将此筛选器添加到OnBeforeRequest:

代码语言:javascript
复制
if (oSession.host.toLowerCase() == "192.168.1.2" || oSession.host.toLowerCase() ==          "192.168.1.2:80") 
{
     oSession.host = "192.168.1.2:8081";

     if (oSession.PathAndQuery=="/") 
     {
        oSession.PathAndQuery="/ocpp15/";

        var strBody1 = oSession.GetRequestBodyAsString ();
        strBody1 = strBody1.replace("http://172.28.0.30/","http://172.28.0.30:8081/ocpp15/");
        oSession.utilSetRequestBody (strBody1);
     }
}

最后一个主体替换是用于soap To字段,该字段有时会被使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22097571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档