wsdl soap exception - asp.net

Having trouble with soap exceptions.
I'm throwing soap exception in asp.net web service and have to somehow get that exception (in form of xml) to show in browser, like this:
SOAP 1.1
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault><faultcode>soap:Client</faultcode>
<faultstring></faultstring>
<detail>
<Error>
<ErrorNumber>1</ErrorNumber>
<ErrorMessage>Error...</ErrorMessage>
</Error>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Throwing exception from web service:
XmlDocument doc = new XmlDocument();
XmlNode detailNode = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);
XmlElement details = doc.CreateElement("Error");
XmlElement detailchild1 = doc.CreateElement("ErrorNumber");
detailchild1.InnerText = "1";
XmlElement detailchild2 = doc.CreateElement("ErrorMessage");
detailchild2.InnerText = "Error...";
details.AppendChild(detailchild1);
details.AppendChild(detailchild2);
detailNode.AppendChild(details);
throw new SoapException("Fault", SoapException.ClientFaultCode, "", details);
If I test it with windows application that calls that service, I can catch exception and extract all details so it seems that everything works with creating xml and throwing exception.
But all I'm getting from browser is internal error 500, which is according to other answers I found normal behaviour. Can I somehow get that xml in browser instead of internal error 500, maybe by changing web.config, IIS settings...

shouldn't this
throw new SoapException("Fault", SoapException.ClientFaultCode, "", details);
be
throw new SoapException("Fault", SoapException.ClientFaultCode, "", detailNode);
?

Related

WCF - Error in deserializing body of reply message for operation 'getWorkOrderStatus'. OperationFormatter encountered an invalid Message

I receive the following error when I try to get a work order status through WCF API call:
Error in deserializing body of reply message for operation 'getWorkOrderStatus'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'getWorkOrderStatusResponse' and namespace ''. Found node type 'Element' with name 'SOAP-ENV:getWorkOrderStatusResponse' and namespace 'http://schemas.xmlsoap.org/soap/envelope/'
This is a new .Net Core project (4.6.1.). I have created the proxy classes using srvcutil 4.6.1 from https://www.fieldnation.com/api/v3.3/fieldnation.wsdl. I had to comment out some of the attributes that were auto generated since .net core doesn't seem to have them. It is most likely one of these causing the issue but I don't know what is the workaround.
This is the actual response I get back using SOAP UI:
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:getWorkOrderStatusResponse>
<return xsi:type="xsd:string">Assigned</return>
</SOAP-ENV:getWorkOrderStatusResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here is anything I could find that seemed relevant in the generated code:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
//[System.ServiceModel.MessageContractAttribute(WrapperName="getWorkOrderStatusResponse", WrapperNamespace="", IsWrapped=true)]
[System.ServiceModel.MessageContractAttribute(WrapperName = "SOAP-ENV:getWorkOrderStatusResponse", WrapperNamespace = "http://schemas.xmlsoap.org/soap/envelope/", IsWrapped = true)]
public partial class getWorkOrderStatusResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public string #return;
public getWorkOrderStatusResponse()
{
}
public getWorkOrderStatusResponse(string #return)
{
this.#return = #return;
}
}

ASP.NET MVC Sitemap.xml error

I have a valid sitemap.xml file. The problem arises when I try to serve this file as a sitemap.xml. I get the following error:
This page contains the following errors:
error on line 1 at column 95: Extra content at the end of the document
Below is a rendering of the page up to the first error.
When I inspect /sitemap.xml from browser each element tag gets this added to it.
<url xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
the rest
</url>
Here is how I return the file from the controller:
XmlDocument xml = new XmlDocument();
xml.Load(#"C:\sitemap.xml");
return Content(xml.DocumentElement.InnerXml, "application/xml");
Here is an example of the file I have and trying to return
<?xml version="1.0" encoding="utf-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>LINK</loc>
</url>
THE REST OF URLS
</urlset>
I have tried switching the "application/xml" to "text/xml" but didn't solve this problem. Am I not using XmlDocument correctly or am I not fully understanding what happens with return Content()?
Any help is appreciated.
Thank you
What ended up fixed this was a simple fix.
XmlDocument xml = new XmlDocument();
xml.Load(#"C:\sitemap.xml");
return Content(xml.DocumentElement.InnerXml, "application/xml");
Changed to
XmlDocument xml = new XmlDocument();
xml.Load(#"C:\sitemap.xml");
return Content(xml.DocumentElement.OuterXml, "application/xml");
Hope this helps someone later.

Unregistered SOAP Client 3.0 on Windows Server

I've developed a Web Application (web site) using VS 2010 and VB.NET. I'm able to run the application successfully from VS. But when I Publish and upload it on my hosting server this error message occurs.
Retrieving the COM class factory for component with CLSID {7F017F97-9257-11D5-87EA-00B0D0BE6479} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I've downloaded the SOAP toolkit 3.0 and imported it in my application reference. here is my code:
Imports MSSOAPLib30
Dim objSoapClient As New SoapClient30 '=== Create an instance of SoapClient
'=== Set Client Properties
objSoapClient.ClientProperty("ServerHTTPRequest") = True
'=== Retrieve KWMP web services WSDL
Call objSoapClient.mssoapinit("https://example.com/ReferencePayment?WSDL", "ReferencePayment")
'=== Set connection property to be over SSL
objSoapClient.ConnectorProperty("UseSSL") = False
'=== Now consume the web sevices according to KWMP Specification
Dim output As String = objSoapClient.verifyTransaction(RCode, "00105952-129251")
--Update--
except the method above, I was thinking of using POST web method to consume the SOAP XML.
here is the xml request generated by WCF Test Client:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" />
</s:Header>
<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<q1:verifyTransaction xmlns:q1="urn:Foo">
<String_1 xsi:type="xsd:string">12345678901234567890</String_1>
<String_2 xsi:type="xsd:string">00109902-129251</String_2>
</q1:verifyTransaction>
</s:Body>
</s:Envelope>
and I have method to consume the SOAP XML which returns Internal Server Error 500 !!!!! You think which part is wrong ?!
Public Function ServiceCall(RefCode As String) As String
Dim resultXml As String
Dim wbrqst As WebRequest = WebRequest.Create("https://modern.enbank.net/ref-payment/ws/ReferencePayment?WSDL")
Dim httpreq As HttpWebRequest = DirectCast(wbrqst, HttpWebRequest)
httpreq.Method = "POST"
httpreq.ContentType = "Content-Type: text/xml; charset=utf-8"
httpreq.Headers.Add("SOAPAction", "https://modern.enbank.net/ref-payment/ws/ReferencePayment")
'httpreq.Headers.Add("<Action s:" + "ReferencePayment>")
httpreq.ProtocolVersion = HttpVersion.Version11
httpreq.Credentials = CredentialCache.DefaultCredentials
Dim requestStream As Stream = httpreq.GetRequestStream()
Dim streamWriter As New StreamWriter(requestStream, Encoding.ASCII)
Dim sb As New StringBuilder()
sb.Append("<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>")
sb.Append("<s:Body s:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>")
sb.Append("<q1:verifyTransaction xmlns:q1='urn:Foo'>")
sb.Append("xml:xsd='http://www.w3.org/2001/XMLSchema'")
sb.Append("<verifyTransaction xmlns='urn:Foo'")
sb.Append("<String_1 xsi:type='xsd:string'>12345678901234567890</String_1>")
sb.Append("<String_2 xsi:type='xsd:String'>00109902-129251</String_2>")
sb.Append("</q1:verifyTransaction> </s:Body></s:Envelope>")
streamWriter.Write(sb.ToString())
streamWriter.Close()
Dim wr As HttpWebResponse = DirectCast(httpreq.GetResponse(), HttpWebResponse)
Dim srd As New StreamReader(wr.GetResponseStream())
resultXml = srd.ReadToEnd()
Return resultXml
End Function
There appears to be a problem with that tool, you may want to use the WCFTest Client, which should work with you soap message, thise can be found from within the VS2010 folder
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe
Just add the service you want to open, it should then create a client proxy for you on the fly.
Update:
You may want to use add web reference and create a webservice project as part of a VS project.
Hope this helps.
Cheers

Weblogic could not find resource adapter with "correct" JNDI name for binding

I am trying to bind my message driven bean with Oracle JCA file adapter (which is included in the SOA suite) on Weblogic 10.3.5. So that my MDB can get notified when there is any .txt file is moved to specific directory.
After launching a Weblogic domain with SOA features supported, the file adapter is automatically deployed. On Weblogic console I can see the file adapter is deployed as a "Resource Adapter", health is "OK", state is "Active", as shown below:
Also I run the tests of the file adapter, and they all passed:
So I think the file adapter is correctly deployed and should be functional.
Then my message driven bean code looks like this:
import java.util.logging.Logger;
import javax.ejb.MessageDriven;
import javax.resource.ResourceException;
import javax.resource.cci.MessageListener;
import javax.resource.cci.Record;
#MessageDriven
public class FileAdapterClientMDB implements MessageListener {
private Logger logger = Logger.getLogger(FileAdapterClientMDB.class.getName());
public FileAdapterClientMDB() {
}
#Override
public Record onMessage(Record record) throws ResourceException {
logger.info("Received record: " + record);
return record;
}
}
Here are the content of my ejb-jar.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
<display-name>MockEJB</display-name>
<enterprise-beans>
<message-driven>
<description>EMessage Driven Bean as File Adapter Client</description>
<display-name>FileAdapterClientMDB</display-name>
<ejb-name>FileAdapterClientMDB</ejb-name>
<ejb-class>com.test.FileAdapterClientMDB</ejb-class>
<messaging-type>javax.resource.cci.MessageListener</messaging-type>
<transaction-type>Container</transaction-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>physicalDirectory</activation-config-property-name>
<activation-config-property-value>C:\dataDir</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>deleteFile</activation-config-property-name>
<activation-config-property-value>true</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>pollingFrequency</activation-config-property-name>
<activation-config-property-value>10</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>includeFiles</activation-config-property-name>
<activation-config-property-value>.*\.txt</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>minimumAge</activation-config-property-name>
<activation-config-property-value>0</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</ejb-jar>
And my weblogic-ejb-jar.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-ejb-jar xmlns:wls="http://www.bea.com/ns/weblogic/weblogic-ejb-jar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://www.bea.com/ns/weblogic/weblogic-ejb-jar http://www.bea.com/ns/weblogic/weblogic-ejb-jar/1.0/weblogic-ejb-jar.xsd">
<!--weblogic-version:10.3-->
<wls:weblogic-enterprise-bean>
<!--options:RESOURCE_ADAPTER_JNDI-->
<wls:ejb-name>FileAdapterClientMDB</wls:ejb-name>
<wls:message-driven-descriptor>
<wls:resource-adapter-jndi-name>eis/FileAdapter</wls:resource-adapter-jndi-name>
</wls:message-driven-descriptor>
<wls:jndi-name>FileAdapterClientMDB</wls:jndi-name>
<wls:local-jndi-name>FileAdapterClientMDB</wls:local-jndi-name>
</wls:weblogic-enterprise-bean>
</wls:weblogic-ejb-jar>
While deploying the EAR project, I got this message:
<20.4.2012 22:42:11 CEST> <Warning> <EJB> <BEA-010221> <The Message-Driven EJB:
FileAdapterClientMDB is unable to bind to the JCA resource adapter: eis/FileAdapter.
The Error was: No deployed ResourceAdapter with adapter JNDI name = 'eis/FileAdapter' was found.>
I have no idea why Weblogic complain this, since the "eis/FileAdapter" JNDI name is mentioned in the official user guide of the adapter. Also I can see it in Weblogic's JNDI tree:
What's more, when I run the code below in my testing web service:
try {
final Context context = new InitialContext();
final Object obj = context.lookup("eis/FileAdapter");
System.out.println("eis/FileAdapter => " + obj);
} catch (NamingException e) {
e.printStackTrace();
}
It prints out "eis/FileAdapter => oracle.tip.adapter.file.FileConnectionFactory#ff51dc", which means the JNDI name is correct!
So my question is, why Weblogic could not find resource adapter with a "correct" JNDI name for binding? Could someone give me some ideas on how to solve it?
as long as you don't see this warning repeating you have nothing to worry. It just shows that in the order of deployment when the MDB was getting deployed it could not get the adapter. Note an MDB keeps trying to connect every 5 secs so if the warning continues to fill the log then that means the MDB has not been able to get the adapter meaning its not working, if you saw the warning only once you can safely ignore it or change the order of deployment and push the MDB little later.

Does anyone know if the crossdomain policy file at salesforce.com has changed?

Suddenly my Flex Apps can no longer connect to salesforce.com via its API, I am getting a security sandbox violation. Login credentials are correct, I have tried them via a different means, and I have obfuscated them below.
This was working fine earlier today and I have not been coding since then.
Anyone else come across this or know what's going on?
Here is the exception returned to my app
Method name is: login
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer connected.
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer sending message 'B89E5879-D7F7-E91E-2082-BBEE231054DD'
'direct_http_channel' channel sending message:
(mx.messaging.messages::HTTPRequestMessage)#0
body = "<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="urn:partner.soap.sforce.com"/><se:Body><login xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com"><username>simon.palmer#***.com</username><password>***</password></login></se:Body></se:Envelope>"
clientId = (null)
contentType = "text/xml; charset=UTF-8"
destination = "DefaultHTTPS"
headers = (Object)#1
httpHeaders = (Object)#2
Accept = "text/xml"
SOAPAction = """"
X-Salesforce-No-500-SC = "true"
messageId = "B89E5879-D7F7-E91E-2082-BBEE231054DD"
method = "POST"
recordHeaders = false
timestamp = 0
timeToLive = 0
url = "https://www.salesforce.com/services/Soap/u/11.0"
Method name is: login
*** Security Sandbox Violation ***
Connection to https://www.salesforce.com/services/Soap/u/11.0 halted - not permitted from https://localhost/pm_server/pm/pm-debug.swf
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer acknowledge of 'B89E5879-D7F7-E91E-2082-BBEE231054DD'.
'A997F86A-36E9-DDDC-EC6B-BBEE23101466' producer fault for 'B89E5879-D7F7-E91E-2082-BBEE231054DD'.
Comunication Error : Channel.Security.Error : Security error accessing url : Destination: DefaultHTTPS
Error: Request for resource at https://www.salesforce.com/services/Soap/u/11.0 by requestor from https://localhost/pm_server/pm/pm-debug.swf is denied due to lack of policy file permissions.
You have to make sure to load the policy from the /services tree, the default policy at the root won't help you. You need to load this policy https://www.salesforce.com/services/crossdomain.xml
The solution to this problem was to set the server protocol and url as follows:
apex = new Connection();
apex.serverUrl = "https://na3.salesforce.com/services/Soap/u/14.0";
apex.protocol = "https";
However, this seems to create a secondary issue of users being locked out, so the issue of non-connectivity remains.
Update: salesforce.com have acknowledged a bug. See my other related post.
Did you recently upgrade to flash player 10? Flash player 10 changes the way policy files work to some degree, and the crossdomain.xml file needs to be updated to address this. In short, Salesforce.com probably isn't prepared for users upgrading to Flash Player 10 yet.
I resolve this issue accessing to the Flash Player Configuration Panel(I just recommend it in a development environment), in the "Global Security" tab, select Always Allow.
Regards.
I am uploading a file from flex to Google docs. Everything is working in the local file however, when we upload the SWF file as S-controls in Salesforce (sandbox), an error appears upon connecting to Google. Please see error below:
Error:[FaultEvent fault=[RPC Fault faultString="Security error accessing url"
faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTPS"]
messageId="1F812836-1318-B845-AC01-F51AB1D11518" type="fault" bubbles=false
cancelable=true eventPhase=2]
We tried the following solutions below but nothing seems to work:
FLEX:
- Add the crossdomain.xml in the bin-debug folder: below is the content of the cross domain policy.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" secure="false" />
<allow-http-request-headers-from domain="*" headers="*" secure="false" />
</cross-domain-policy>
Used flash.system.security.allowinsecuredomain/allowdomain(“*”) in the initialization.
Also tried in the connection.protocol set to http
Salesforce:
Disabled the protocol security in the remote site settings
o Setup -> Administration Setup -> Security Controls -> Remote Site Settings
 URL: http://www.google.com.ph
There’s no problem in connection to Salesforce but upon initialization of the uploading page the security error will appear specifically in the onErrorFault function. Below are code snippets:
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="534" height="462" verticalScrollPolicy="off" horizontalScrollPolicy="off"
creationComplete="init()" showCloseButton="true" close="{this.closeWindow(event)}" roundedBottomCorners="true">
<mx:Script>
<![CDATA[
private function init():void{
Security.allowInsecureDomain("*");
//<salesforce:Connection id="apex" sendRequest="sendRequestListener(event)" serverUrl="http://www.salesforce.com/services/Soap/u/10.0" protocol="http"/>
RESTProxyTest();
send_data();
arrAddedFiles = new Array();
this.uploadGrid.dataProvider= this.acFiles;
this.title = "Attachment: "+this.selectedTimeSheetDetail.Project.label;
}
public function RESTProxyTest():void
{
_conn = new NetConnection();
_conn.addEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
_conn.addEventListener(IOErrorEvent.IO_ERROR, doIOError);
_conn.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doSecurityError);
_conn.addEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
_conn.objectEncoding = ObjectEncoding.AMF3;
_conn.connect(_url);
_responder = new Responder(onResult, onFault);
}
private function send_data():void {
userRequest.url = getLoginURL();
userRequest.addEventListener(ResultEvent.RESULT, httpResult);
userRequest.addEventListener(FaultEvent.FAULT, onErrorFault);
userRequest.send();
}
private function onErrorFault(obj:FaultEvent):void
{
Alert.show("Error:"+obj.toString());
}
private function httpResult(obj:ResultEvent):void
{
trace(obj.toString());
var result:String = obj.result as String;
var pos:int = result.lastIndexOf("Auth=");
var auth:String = result.substr(pos + 5);
txtAuth.text = StringUtil.trim(auth);
placeCall();
}
protected function placeCall():void
{
trace("placeCall");
var headers:Array = ["Authorization: " + "GoogleLogin auth=" + StringUtil.trim(txtAuth.text)];
var postVars:Array = [];
var uri:String = "http://docs.google.com/feeds/documents/private/full?showfolders=true";
_conn.call("RESTProxy.request", _responder, uri, "get", new Array(), postVars, headers);
}
private function getLoginURL():String
{
var url:String = 'https://www.google.com/accounts/ClientLogin?accountType=HOSTED_OR_GOOGLE&' +
'Email=' + this.session.config.gmail + '&' +
'Passwd=' + this.session.config.password + '&service=writely';
return url;
}
]]>
</mx:Script>
<mx:HTTPService id="userRequest" useProxy="false" method="POST" contentType="application/x-www-form-urlencoded" showBusyCursor="true"/>

Resources