You need to sign in to do that
Don't have an account?
mcclurec
How do I consume Outgoing Messages with WCF in .Net 4.0
I feel like maybe I'm asking an obvious question, but I'm just stuck. I've been trying to follow along with the Salesforce example of how to build a .Net SOAP listener, but I've hit the wall. Also, all of the code samples seem outdated and old. Is anyone using .Net 4 to consume a Salesforce SOAP payload? Could you point me to a good example? Thanks in advance.
Not sure if this is the best way to do it, but I ended up building an ashx page with the following code:
public void ProcessRequest(HttpContext context)
{
context.Request.ContentType = "text/xml";
context.Request.ContentEncoding = System.Text.Encoding.UTF8;
HttpRequest request = null;
request = context.Request;
string sfXMLPayload = "";
Stream strm = response.InputStream;
StreamReader sr = new StreamReader(strm);
string sfXML = sr.ReadToEnd();
sfXMLPayload = sfXML;
WriteTextFile( sfXMLPayload);
}
public void WriteTextFile(string inputStr)
{
string text = inputStr;
System.IO.File.WriteAllText(@"C:\temp\sfXML.xml", text);
}
All Answers
While the specifics are for an older version of .NET, the general steps should be the same, import the WSDL as a server implementation rather than client, implement your class, and deploy.
Hmmm, maybe I need a 10,000 foot view :)
I'm new to WCF and even newer to consuming SOAP through it. Let me lay out my understanding and then you can fill in the blanks.
On the salesforce side I have created a workflow that pushes a package (I'm assuming SOAP) to a URL I define, www.mydomain.com/salesforce/V1/receiver/managers.asmx
In my project I have created a web reference to the wsdl.
Then on the managers.asmx page I can do something like:
sForceManagers.Region__c managerObject = new sForceManagers.Region__c();
Within this object I can see all the elements I care about so I know the WSDL is coming in correctly, but then what?
If this is right to this point, what I then want to do is dissect the object and push pieces of it into my database.
What I am missing is how does the page know that when it is called to wait for a SOAP package, consume it and then work with the data from it?
I feel like I am 90% there, but the 10% that is missing has got to be really straightforward and I am not not thinking the right way. Thanks!!
Hi,
what you should do is to generate a web service from the WSDL you got from SFDC. The web service should then be placed on the URL you defined.
If you create a web reference with that WSDL your code will become a client (you'll consume the web service). But you want to build a service. I don't know if there is an easy way to generate a web service class/interface with VS (if you do, please enlighten me) but you can do it from command line with the wsdl.exe program.
Have a look at this Stackoverflow article.
http://stackoverflow.com/questions/548314/create-an-asmx-web-service-from-a-wsdl-file
I hope it helps!
Martin
Thanks Haagen for the reply. My fear is that that method is the "old" way of doing it. It seems like all those posts have someone saying this is a deprecated method. I'm still sludging through the mud here, will report if I get it figured out. I know it can't be that hard, my head just isn't working how it should be...
I think that SF.com "Outgoing Message" simply does a HTTP Post of the name-value pairs.
To consume a WCF web service from SF.com, one should use APEX to create an SOAP XML to post from a Trigger / other scheduled jobs.
It's going the other way, I want to consume something sforce sends me.
Not sure if this is the best way to do it, but I ended up building an ashx page with the following code:
public void ProcessRequest(HttpContext context)
{
context.Request.ContentType = "text/xml";
context.Request.ContentEncoding = System.Text.Encoding.UTF8;
HttpRequest request = null;
request = context.Request;
string sfXMLPayload = "";
Stream strm = response.InputStream;
StreamReader sr = new StreamReader(strm);
string sfXML = sr.ReadToEnd();
sfXMLPayload = sfXML;
WriteTextFile( sfXMLPayload);
}
public void WriteTextFile(string inputStr)
{
string text = inputStr;
System.IO.File.WriteAllText(@"C:\temp\sfXML.xml", text);
}
"[...] the general steps should be the same [...]"
So it should not be a major effort for you guys to provide a new set of samples, right? Rather than leaving users, me either, struggling with them!!
Cheers