I am trying to log the soap request and response messages of a service in C#. I have a ready made soap extension which does all this, however I am having trouble adding it to the service method.
Since I have a service reference added in my VS project and not a web service reference, when i check the reference file for this service, I don't see the method which is doing the invoking of the remote service. All the examples I saw were of adding to a web service, which has a different reference format.
How can I log the soap messages in this case?
Soap extension is only for using ASMX based service or client = Add web reference. Once you used Add service reference you are using WCF client API instead and you cannot use Soap extension. You must create message inspector instead.
If you need message logging only for debugging purpose you can use built in WCF message logging.
There is an another way to see XML SOAP - custom MessageEncoder. The main difference from IDispatchMessageInspector / IClientMessageInspector is that it works on lower level, so it captures original byte content including any malformed xml.
In order to implement tracing using this approach you need to wrap a standard textMessageEncoding with custom message encoder as new binding element and apply that custom binding to endpoint in your config.
Also you can see as example how I did it in my project -
wrapping textMessageEncoding, logging encoder, custom binding element and config.
Related
I have an azure function app (v1, with no possibility for upgrading, unfortunately) with an endpoint receiving JSON via POST requests, doing some computation and returning JSON in the response. This endpoint needs to be made SOAP-compatible, meaning that it should receive SOAP requests and return SOAP responses and also be able to provide a WSDL file.
Using the SOAP mapper in API Management is not an option, due to its limitations.
The methods I have tried are:
Create a WCF service and try to delegate the HTTP request to it from the Azure function endpoint. This didn't seem to work because the corresponding handler in WCF can only receive a request via its own HTTP endpoint (which does not seem to be exposable via the azure function endpoint), but cannot be called from within the code.
Use an ASP.net web application with SoapCore as a starting point and try to migrate it to an azure function. This doesn't seem possible because of a completely different structure. SoapCore is attached to the ASP.net app instance as a middleware, whereas azure function does not provide the means to use middleware.
Parse the SOAP request manually, convert it to JSON, do the computation, convert the result back to a SOAP message and return it. The seems very hacky and also the WSDL must be created and served manually. Despite these drawbacks, I'm leaning towards this solution because of the unfeasibility of the first two.
Is there any other possible solution that I have might missed?
If you are using Azure API Management , then below option works;
You can write transformation policies at the service or endpoint level - JSON to SOAP refer: https://learn.microsoft.com/en-us/azure/api-management/api-management-transformation-policies#convert-json-to-soap-using-a-liquid-template
Also refer this link Expose REST API as SOAP via Azure API Management would help.
I'm trying to replace a WCF service based on BizTalk and as far as I know it was made using the BizTalk wizard for publishing WCF services. In order to resolve the problem I did something tricky, I exposed an ashx handler and read the soap. We want the department that consumes the service to not make any change except the url (.svc-> .ashx) and maybe another minor change like change binding. The problem I have now is the message for some reason uses more than one soap request with security tokens like:
I suppose is related to the service model configuration (credentials i think) in the WCF client,
Is there any way to force the binding in order to send just only one no encrypted-request?
We are currently developing some new systems to replace parts of several legacy systems.
We have some new WCF web services which will sit alongside existing ASMX web services.
The ASMX web services authenticate via a Soap Header Context object with 4 custom properties including a token (previously generated and returned at login) which are then validated.
We are not re-writing the validation code yet and the login is still being handled by the existing ASMX services, so we are required to call the existing validator passing in a Context object with the 4 properties from the WCF service application.
How do we capture the 4 properties via the WCF service?
A previous WCF project implemented WCFExtras+ to replicate the Soap Header over WCF.
We can do that again but would prefer a native WCF approach.
I have found options such as custom UserNamePasswordValidator or ServiceAuthorizationManager but have been unable to determine how to exactly apply these to our specific requirements.
Is this possible? How?
After much googling I wrote my own custom behaviour using IOperationBehavior, IContractBehavior and IDispatchMessageInspector
I would like to connect to a SOAP webservice (HP Operations Manager Incident Web Service) using a .NET client based on code generated by adding a service reference. The generated proxy creates a client that implements the DuplexClientBase class. The service is IIS hosted with a self-signed certificate and I need to sign in using basic authentication.
I ran into two problems trying to connect to this service:
I have not yet been able to find the right binding configuration. Either the binding does not support duplex or https traffic with basic authentication.
When adding a .NET 2.0 web service reference (the binding issue is not there) I am able to connect to the service but the “Action” header element which is required by the service and should look like <a:Action s:mustUnderstand="1"> http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate</a:Action> is not included in the header. When I create a SoapExtensions and inspect the contents of the Action property of the SoapMessage object in the ProcessMessage(SoapMessage message) method it contains the right value but the property is not serialized in the message header.
I would like to know if any of you could suggest what to do:
Proceed with a 2.0 legacy reference and find a way to add the Action element in the SOAP header. (eg adding a SoapExtension)
Fix the binding a find a way to connect to the https site with faulty certificate (wsDualHttpBindingdoes not support HTTPS, BasicHttpBinding does not support duplex, PollingDuplexHttpBinding does not seem to work in a console application)
Try to generate the code in a way that no duplex communication is required. Is this possible?
It is possible to make a .NET 2.0 client support WS Addressing. You can accomplish this by downloading and installing Webservice Enhancements 3.0 (WSE). http://www.microsoft.com/en-us/download/details.aspx?id=14089
When you add a reference to the Microsoft.Web.Services3 assembly and change the code generated by adding the web service reference. Change System.Web.Services.Protocols.SoapHttpClientProtocol into Microsoft.Web.Services3.WebServicesClientProtocol and the code will support WS Adressing. The action element will now be added to the SOAP header.
Although this workaround does the job I still would prefer a WCF service reference connection.
Just trying to wrap my head around SOAP vs REST. We currently have some asmx web services, mostly used between our own JavaScript and server code (not a public API). When I specify my method as a ScriptService and specify a ResponseFormat of Json, is it still considered just a SOAP service? It still doesn't feel RESTful to me, but maybe thats because of the way my "resources" are designed (not well/fully represented by rest).
EDIT: Reading more I might be confusing the format (JSON vs XML) with the fact that most descriptions of the SOAP protocol tie in XML. For example, wikipedia states:
It relies on Extensible Markup
Language (XML) for its message format
To me logically that says if I'm using JSON I must not be using SOAP.
This isn't exactly what you asked, but ASMX services are not RESTful if you're calling them from JavaScript and retrieving JSON. You must make a POST request to ASMX services to get JSON out of them, even if the request is idempotent and only retrieves data. In a RESTful API, a GET request would be used in that case, not POST.
That's not to say that the lack of RESTfulness is an actual problem for a private API. I've found ASMX services as a JSON-based service layer for AJAX callbacks works great in practice.
You define what kind of requests are made to you web service (asmx). Many protocols are allowed:
HTTP POST,
HTTP GET,
SOAP 1.1,
SOAP 1.2,
etc... OR you can block any of them.
When you call the web service with javascript you can use POST or GET. It doesn't matter. The trick is what type of content you tell the service to return in these calls. You can tell the service to send you JSON or you can tell the service to send you XML.
When you create a service client in Visual Studio to connect to a ASMX service, Visual studio will try to access the WSDL for the service and the client will be in charge of generating the SOAP envelopes to communicate with the service and in this case you will send and receive XML because thats what the client and server have agreed to use to communicate.