0

I have device (charger) which sends SOAP-messages to an IP I where I will receive status reports but it is always sent in the root directory and is not changeable: http://192.168.1.2/

I made a WCF service self hosted which I want to receive those messages. But I can not find any information about url-rewriting or listening to something else than the name of the service, in my case it becomes http://192.168.1.2/ocpp15

Is it possible to rewrite/route from / to /ocpp15/ or from /ocpp15/ to / in any way?

Hosting in a Windows service

        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();

Service contact

Generated from a WSDL-file with /sc option

[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.....

Service

public class Ocpp15 : IOcpp15
{
    public AuthorizeResponse Authorize(AuthorizeRequest request)
    {
        return new AuthorizeResponse { idTagInfo = ValidateRequest(request) };
    }
    and so on.....
kiteloop
  • 404
  • 4
  • 11

1 Answers1

0

I have not found any solution to this in WCF but a hack using Fiddler. Set fiddler to listen on port 80 and accept external requests. Listen to WCF on another port, in my case 8081.

Add this filter to OnBeforeRequest:

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);
     }
}

That last body-replace is for the soap To field which is used sometimes.

kiteloop
  • 404
  • 4
  • 11