Axis2 with MTOM: Unexpected end of stream while reading a SOAP fault - axis2

I'm trying to read a soap fault from an axis2 client, with mtom enabled.
Axis2 version is 1.6.2, both for client and server.
The wsdl part related to the fault:
.....
<xs:simpleType name="CodiceErroreDiTrasferimentoType">
<xs:annotation>
<xs:documentation>Codici di errore generati durante il trasferimento del pacchetto di versamento</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="ERRORE_DI_SISTEMA"/>
...
</xs:restriction>
</xs:simpleType>
....
<xs:element name="ErroreDiTrasferimento">
<xs:annotation>
<xs:documentation>Errore generato nella fase di trasferimento del pacchetto</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:restriction base="ingest:ErroreType">
<xs:sequence>
<xs:element name="Codice" type="ingest:CodiceErroreDiTrasferimentoType"/>
<xs:element name="Messaggio" type="xs:string"/>
<xs:element name="Riferimento" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
....
<wsdl:message name="IngestFault">
<wsdl:part name="fault" element="ingest:ErroreDiTrasferimento"/>
</wsdl:message>
....
<wsdl:operation name="InviaPacchettoDiVersamento">
<wsdl:input message="tns:InviaPacchettoDiVersamentoRequest"/>
<wsdl:output message="tns:InviaPacchettoDiVersamentoResponse"/>
<wsdl:fault name="IngestFault" message="tns:IngestFault"/>
</wsdl:operation>
....
<wsdl:operation name="InviaPacchettoDiVersamento">
<soap:operation soapAction="urn:InviaPacchettoDiVersamento"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="IngestFault">
<soap:fault name="IngestFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
During the reading/parsing of the IngestFault this exception occurs:
org.apache.axis2.AxisFault: org.apache.axiom.ext.io.StreamCopyException: Error reading from source
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at test.cin.conserva.versamento.service.TrasferimentoStub.inviaPacchettoCompresso(TrasferimentoStub.java:1076)
at test.cin.conserva.ingest.TransferServiceTestCase.testScenarioErrore02(TransferServiceTestCase.java:188)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.axiom.om.OMException: org.apache.axiom.ext.io.StreamCopyException: Error reading from source
at org.apache.axiom.attachments.PartContentFactory.createPartContent(PartContentFactory.java:153)
at org.apache.axiom.attachments.PartImpl.fetch(PartImpl.java:176)
at org.apache.axiom.attachments.PartImpl.getContent(PartImpl.java:149)
at org.apache.axiom.attachments.PartImpl.getInputStream(PartImpl.java:224)
at org.apache.axiom.attachments.PartDataSource.getInputStream(PartDataSource.java:44)
at javax.activation.DataHandler.getInputStream(DataHandler.java:223)
at org.apache.axiom.attachments.MIMEMessage.getRootPartInputStream(MIMEMessage.java:196)
at org.apache.axiom.attachments.Attachments.getRootPartInputStream(Attachments.java:248)
at org.apache.axiom.attachments.Attachments.getSOAPPartInputStream(Attachments.java:224)
at org.apache.axis2.builder.MIMEBuilder.processDocument(MIMEBuilder.java:78)
at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:179)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
... 31 more
Caused by: org.apache.axiom.ext.io.StreamCopyException: Error reading from source
at org.apache.axiom.attachments.utils.BAAOutputStream.readFrom(BAAOutputStream.java:114)
at org.apache.axiom.attachments.impl.BufferUtils.inputStream2OutputStream(BufferUtils.java:76)
at org.apache.axiom.attachments.PartContentFactory.createPartContent(PartContentFactory.java:119)
... 43 more
Caused by: org.apache.james.mime4j.MimeIOException: Unexpected end of stream
at org.apache.james.mime4j.io.MimeBoundaryInputStream.verifyEndOfStream(MimeBoundaryInputStream.java:205)
at org.apache.james.mime4j.io.MimeBoundaryInputStream.readAllowed(MimeBoundaryInputStream.java:129)
at org.apache.james.mime4j.io.MimeBoundaryInputStream.read(MimeBoundaryInputStream.java:152)
at org.apache.james.mime4j.io.BufferedLineReaderInputStream.fillBuffer(BufferedLineReaderInputStream.java:111)
at org.apache.james.mime4j.io.BufferedLineReaderInputStream.read(BufferedLineReaderInputStream.java:158)
at org.apache.james.mime4j.io.LineReaderInputStreamAdaptor.read(LineReaderInputStreamAdaptor.java:67)
at org.apache.axiom.attachments.utils.BAAOutputStream.readFrom(BAAOutputStream.java:112)
... 45 more
Caused by: org.apache.james.mime4j.MimeException: Unexpected end of stream
... 52 more
The client can successfully read soap message other than soap faults.
Any suggestion?
Thanks.

I found the solution: the error occurs when the client cannot parse the SOAP fault because of limitation of axis 2 (in my case it cannot parse the element ErroreDiTrasferimento as a restriction of a complex type) or because the client web service stub is not updated to the current wsdl.
I think the axis exception is not very clear ;)

Related

Where to set username and password in a Web Service client?

I was provided this WSDL, and I have to develop a client for it (I've been making questions here about it lol).
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:ManterFornecedor" xmlns:s0="urn:ManterFornecedor" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema elementFormDefault="qualified" targetNamespace="urn:ManterFornecedor">
<xsd:element name="Novo" type="s0:InputMapping1"/>
<xsd:complexType name="InputMapping1">
<xsd:sequence>
<xsd:element name="NO_FORNECEDOR" type="xsd:string"/>
<xsd:element name="DE_CONTRATO" type="xsd:string"/>
<xsd:element name="DH_INICIO" nillable="true" type="xsd:dateTime"/>
<xsd:element name="DH_FIM" nillable="true" type="xsd:dateTime"/>
<xsd:element name="NO_PRODUTO" type="xsd:string"/>
<xsd:element name="IC_STATUS" type="s0:IC_STATUSType" nillable="true"/>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="IC_STATUSType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Ativo"/>
<xsd:enumeration value="Inativo"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="NovoResponse" type="s0:OutputMapping1"/>
<xsd:complexType name="OutputMapping1">
<xsd:sequence>
<xsd:element name="Id" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="AuthenticationInfo" type="s0:AuthenticationInfo"/>
<xsd:complexType name="AuthenticationInfo">
<xsd:sequence>
<xsd:element name="userName" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
<xsd:element minOccurs="0" name="authentication" type="xsd:string"/>
<xsd:element minOccurs="0" name="locale" type="xsd:string"/>
<xsd:element minOccurs="0" name="timeZone" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="NovoSoapOut">
<wsdl:part element="s0:NovoResponse" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="ARAuthenticate">
<wsdl:part element="s0:AuthenticationInfo" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:message name="NovoSoapIn">
<wsdl:part element="s0:Novo" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="PortPortType">
<wsdl:operation name="Novo">
<wsdl:input message="s0:NovoSoapIn"></wsdl:input>
<wsdl:output message="s0:NovoSoapOut"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PortSoapBinding" type="s0:PortPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Novo">
<soap:operation soapAction="urn:ManterFornecedor/Novo" style="document"/>
<wsdl:input>
<soap:header message="s0:ARAuthenticate" part="parameters" use="literal"></soap:header>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ManterFornecedorService">
<wsdl:documentation>Fornecedor</wsdl:documentation>
<wsdl:port binding="s0:PortSoapBinding" name="PortSoap">
<soap:address location="http://somewhere&webService=ManterFornecedor"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I provided the full WSDL, but the important part for the question is
<soap:operation soapAction="urn:ManterFornecedor/Novo" style="document"/>
<wsdl:input>
<soap:header message="s0:ARAuthenticate" part="parameters" use="literal"></soap:header>
<soap:body use="literal"/>
</wsdl:input>
As you can see, input has a ARAuthenticate message in its header, which is
<wsdl:message name="ARAuthenticate">
<wsdl:part element="s0:AuthenticationInfo" name="parameters"></wsdl:part>
</wsdl:message>
<xsd:element name="AuthenticationInfo" type="s0:AuthenticationInfo"/>
<xsd:complexType name="AuthenticationInfo">
<xsd:sequence>
<xsd:element name="userName" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
<xsd:element minOccurs="0" name="authentication" type="xsd:string"/>
<xsd:element minOccurs="0" name="locale" type="xsd:string"/>
<xsd:element minOccurs="0" name="timeZone" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
I used Eclipse's Web Services Explorer to create a WS client to test this webservice, and it worked! This client has username and password fields to be set.
Ok, now I need to take this client exemple code, and implement a standalone (not web UI) solution that gathers info and uses the client to send it to the server. But it's failing, and I believe it's because authentication.
Only place I see username and password being set is in PortSoapBindingStub.createCall():
org.apache.axis.client.Call _call = super._createCall();
if (super.maintainSessionSet) {
_call.setMaintainSession(super.maintainSession);
}
if (super.cachedUsername != null) {
_call.setUsername(super.cachedUsername);
}
if (super.cachedPassword != null) {
_call.setPassword(super.cachedPassword);
}
if (super.cachedEndpoint != null) {
_call.setTargetEndpointAddress(super.cachedEndpoint);
}
if (super.cachedTimeout != null) {
_call.setTimeout(super.cachedTimeout);
}
if (super.cachedPortName != null) {
_call.setPortName(super.cachedPortName);
}
But, where are these cached stuff coming from? I tried to edit this code and manually set them, but keep receiving error:
Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.ArrayIndexOutOfBoundsException: -1
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}hostname:myhost
java.lang.ArrayIndexOutOfBoundsException: -1
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at ManterFornecedor.PortSoapBindingStub.novo(PortSoapBindingStub.java:174)
at ManterFornecedor.PortPortTypeProxy.novo(PortPortTypeProxy.java:50)
at caixa.pedes.br.ManterFornecedor.main(ManterFornecedor.java:43)
Here's my code:
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import ManterFornecedor.*;
public class ManterFornecedor {
public static void main(String[] args) throws RemoteException, ServiceException, MalformedURLException {
InputMapping1 parameters = new InputMapping1(
"fornecedor","contrato",java.util.Calendar.getInstance(), java.util.Calendar.getInstance(),
"produto",IC_STATUSType.Ativo
);
java.net.URL endpoint = new java.net.URL("http://somewhere&webService=ManterFornecedor");
PortPortTypeProxy proxy = new PortPortTypeProxy();
ManterFornecedorServiceLocator locator = new ManterFornecedorServiceLocator();
ManterFornecedor.PortPortType port = locator.getPortSoap();
PortSoapBindingStub client = new PortSoapBindingStub(endpoint,locator);
ManterFornecedor.OutputMapping1 response = proxy.novo(parameters);
System.out.println(response);
}
}
Edit: as you can see, I'm new to Web Service and I'm kinda lost. I don't know exactally why, but the novo() method is available in Proxy, Locator and Stub. I'll read more about these design patterns because I'm new to them too, and using all 3 together is even more troublesome.
What's the best object to use to call WSDL generated operators? Unfortuntely, client code created in Eclipse uses JSP to receive parameters, and I'm not being able to properly isolate exemple code to real client so that I can develop my code and call client's operator.
It would be much easier if client was encapsulated in a unique class where I just had to provide its configs (endpoint, authentication, etc) and then call the operator.
You must put this code before to setRequestHeaders(_call); in the PortTypeSoapBindingStub class
try {
SOAPHeaderElement sopElement = new SOAPHeaderElement("urn:AuthenticationInfo","AuthenticationInfo") ;
sopElement.addChildElement("userName").addTextNode("XXXXX") ;
sopElement.addChildElement("password").addTextNode("XXXX");
sopElement.addChildElement("authentication").addTextNode("");
sopElement.addChildElement("locale").addTextNode("");
sopElement.addChildElement("timeZone").addTextNode("");
_call.addHeader(sopElement);
} catch (Exception e) {
e.printStackTrace();
}
I also struggled to achieve the same, later I found the NTLM Authentication wasn't enabled in the mac machine used at server
The following code worked for me
public static void testNavisionMicrosoft() {
static String baseURL = "file:C://locapath//customer.wsdl";
URL url = null;
try {
url = new URL(baseURL);
} catch (MalformedURLException e) {
e.printStackTrace();
}
URL url2 = null;
try {
url2 = new URL("http://localhost:8080/customer?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
final String username = "user";
final String password = "paswd";
Authenticator.setDefault(new Authenticator() {
#Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password
.toCharArray());
}
});
QName qname = new QName("search for soapActionin your wsdl file",
"search for service name in wsdl file");
Service service = Service.create(url, qname);
CRMCustomerPort proxy = service.getPort(CRMCustomerPort.class);
Map<String, Object> requestContext = ((BindingProvider) proxy)
.getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, username);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, password);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Timeout", Collections.singletonList("10000"));
requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
CRMCustomer data = proxy.read("AIL0003190");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(
"Error occurred in operations web service client initialization",
e);
}
}

Creating a CXF proxy client for WCF file upload

I'm trying to create a WCF service (.Net 4.5 in VS2012) for file uploads that can be consumed by clients in other languages, Java (using CXF) in particular. I've got the WCF side of things working great from .Net clients, but am having some issues on the CXF side.
When I try to generate the proxy in CXF from the WSDL through Eclipse (4.2/Juno), I'm getting an exception that prevents the proxy from being created:
wsdl2java -client -d C:\Users\Ryan\workspace\WcfProxy\.cxftmp/src -classdir C:\Users\Ryan\workspace\WcfProxy\build\classes -p http://tempuri.org/=org.tempuri -impl -validate -exsh false -dns true -dex true -wsdlLocation http://localhost:10186/UploadFile.svc?wsdl -verbose -defaultValues -fe jaxws -db jaxb -wv 1.1 http://localhost:10186/UploadFile.svc?wsdl
wsdl2java - Apache CXF 2.7.0
WSDLToJava Error: Schema Error : src-resolve: Cannot resolve the name 'ns0:StreamBody' to a(n) 'type definition' component.
org.apache.cxf.tools.common.ToolException: Schema Error : src-resolve: Cannot resolve the name 'ns0:StreamBody' to a(n) 'type definition' component.
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.validateSchema(JAXBDataBinding.java:914)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.addSchemas(JAXBDataBinding.java:586)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:392)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.generateTypes(WSDLToJavaContainer.java:603)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:248)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:142)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:300)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:184)
Caused by: org.xml.sax.SAXParseException; src-resolve: Cannot resolve the name 'ns0:StreamBody' to a(n) 'type definition' component.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getGlobalDecl(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDElementTraverser.traverseLocal(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.traverseLocalElements(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
at javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.validateSchema(JAXBDataBinding.java:909)
... 10 more
My WCF service contract is as follows:
<ServiceContract()>
Public Interface IUploadFile
<OperationContract()>
Sub UploadFile(ByVal remoteFile As RemoteFile)
<OperationContract()>
Function DownloadFile() As RemoteFile
End Interface
My WCF message contract (RemoteFile) is as follows:
<MessageContract()> _
Public Class RemoteFile
Implements IDisposable
<MessageHeader(MustUnderstand:=True)> _
Public FileName As String
<MessageHeader(MustUnderstand:=True)> _
Public Length As Long
<MessageBodyMember(Order:=1)> _
Public FileByteStream As System.IO.Stream
Public Sub Dispose() Implements IDisposable.Dispose
If FileByteStream IsNot Nothing Then
FileByteStream.Close()
FileByteStream = Nothing
End If
End Sub
End Class
My WCF service configuration is as follows:
...
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="FileTransferServicesBinding"
transferMode="Streamed"
messageEncoding="Mtom"
maxReceivedMessageSize="10067108864">
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="UploadServiceBehavior" name="Server.UploadFile">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="FileTransferServicesBinding"
contract="Server.IUploadFile" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="UploadServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
...
My WSDL is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="UploadFile" targetNamespace="http://tempuri.org/">
<wsp:Policy wsu:Id="BasicHttpBinding_IUploadFile_policy">
<wsp:ExactlyOne>
<wsp:All>
<wsoma:OptimizedMimeSerialization/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:10186/UploadFile.svc?xsd=xsd1" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://localhost:10186/UploadFile.svc?xsd=xsd0" namespace="http://schemas.microsoft.com/Message"/>
<xsd:import schemaLocation="http://localhost:10186/UploadFile.svc?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="RemoteFile">
<wsdl:part name="parameters" element="tns:RemoteFile"/>
</wsdl:message>
<wsdl:message name="RemoteFile_Headers">
<wsdl:part name="FileName" element="tns:FileName"/>
<wsdl:part name="Length" element="tns:Length"/>
</wsdl:message>
<wsdl:message name="IUploadFile_DownloadFile_InputMessage"/>
<wsdl:portType name="IUploadFile">
<wsdl:operation name="UploadFile">
<wsdl:input wsaw:Action="http://tempuri.org/IUploadFile/UploadFile" name="RemoteFile" message="tns:RemoteFile"/>
</wsdl:operation>
<wsdl:operation name="DownloadFile">
<wsdl:input wsaw:Action="http://tempuri.org/IUploadFile/DownloadFile" message="tns:IUploadFile_DownloadFile_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IUploadFile/DownloadFileResponse" name="RemoteFile" message="tns:RemoteFile"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IUploadFile" type="tns:IUploadFile">
<wsp:PolicyReference URI="#BasicHttpBinding_IUploadFile_policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="UploadFile">
<soap:operation soapAction="http://tempuri.org/IUploadFile/UploadFile" style="document"/>
<wsdl:input name="RemoteFile">
<soap:header message="tns:RemoteFile_Headers" part="FileName" use="literal"/>
<soap:header message="tns:RemoteFile_Headers" part="Length" use="literal"/>
<soap:body use="literal"/>
</wsdl:input>
</wsdl:operation>
<wsdl:operation name="DownloadFile">
<soap:operation soapAction="http://tempuri.org/IUploadFile/DownloadFile" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="RemoteFile">
<soap:header message="tns:RemoteFile_Headers" part="FileName" use="literal"/>
<soap:header message="tns:RemoteFile_Headers" part="Length" use="literal"/>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="UploadFile">
<wsdl:port name="BasicHttpBinding_IUploadFile" binding="tns:BasicHttpBinding_IUploadFile">
<soap:address location="http://localhost:10186/UploadFile.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Obviously the exception indicates it is having an issue creating the stream body type of the message, but does anyone see what I'm doing wrong or need to change to be able to generate a CXF proxy for this WCF service?
EDIT Added WSDL to original post.

WCF Universal service contract and WS-Interoperability compliance

Microsoft MSDN describes the most universal service contract for a request reply operation as
[ServiceContract]
public interface IUniversalRequestReply
{
[OperationContract(Action="*", ReplyAction="*")]
Message ProcessMessage(Message msg);
}
If I make a contract like the one below, using basicHttp binding, it will not be WS-I compliant (using SOAPUI compliance check).
[OperationContract]
Message SomeOperation(Message msg);
I would think the most universal contract also would be the most interoperable.
Can anyone explain why it is not WS-I compliant? And more importantly - will using the Message class make the service less consumable to Java clients?
Any experience using the Message class is appreciated.
EDIT After first answer:
This is the full WSDL showing the service contract and operation contract.
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="UniversalRequestReply" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://localhost:52437/UniversalRequestReply.svc?xsd=xsd0" namespace="http://schemas.microsoft.com/Message"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="IUniversalRequestReply_SomeOperation_InputMessage">
<wsdl:part xmlns:q1="http://schemas.microsoft.com/Message" name="msg" type="q1:MessageBody"/>
</wsdl:message>
<wsdl:message name="IUniversalRequestReply_SomeOperation_OutputMessage">
<wsdl:part xmlns:q2="http://schemas.microsoft.com/Message" name="SomeOperationResult" type="q2:MessageBody"/>
</wsdl:message>
<wsdl:portType name="IUniversalRequestReply">
<wsdl:operation name="SomeOperation">
<wsdl:input wsaw:Action="http://tempuri.org/IUniversalRequestReply/SomeOperation" message="tns:IUniversalRequestReply_SomeOperation_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IUniversalRequestReply/SomeOperationResponse" message="tns:IUniversalRequestReply_SomeOperation_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IUniversalRequestReply" type="tns:IUniversalRequestReply">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="SomeOperation">
<soap:operation soapAction="http://tempuri.org/IUniversalRequestReply/SomeOperation" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="UniversalRequestReply">
<wsdl:port name="BasicHttpBinding_IUniversalRequestReply" binding="tns:BasicHttpBinding_IUniversalRequestReply">
<soap:address location="http://localhost:52437/UniversalRequestReply.svc/basic"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
What the WSI Compliance test fails is not a missing service contract, but the Message input itself:
Name of message that failed: {http://tempuri.org/}IUniversalRequestReply_SomeOperation_InputMessage
Message: name={http://tempuri.org/}IUniversalRequestReply_SomeOperation_InputMessage
Part: name=msg
typeName={http://schemas.microsoft.com/Message}MessageBody
So using this Message class is not WS-I compliant of some reason.
The reason is the service is not complaint is because it does not define any service contract. Universal means this service can consume the soap message generated by any client that calls it. It does not attempt to deserialize the soap message because it never defines a contract of its own. WS-I compliance requires that a service define a static contract that can be expressed in WSDL.

generate wcf server code from wsdl files

Greetings, I would like to generate some contract based on wsdl file. I used svcutil but I suspect it generated it wrong as all contract methods have void returned type. Is there any tool for this purpose?
EDIT:
here is the wsdl file:
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:tns="http://dantek.com.pl/EDItEUR/EDItX/LibraryBookSupply/WebService/CustomerService/20100611/ServiceContract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" targetNamespace="http://mytargetNamespace/ServiceContract" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema targetNamespace="http://mytargetNamespace/ServiceContract/Imports">
<xsd:import namespace="http http://mytargetNamespace/ServiceContract/ServiceContract" />
</xsd:schema>
</wsdl:types>
<wsdl:message name="CustomerService_ProcessMethod_InputMessage">
<wsdl:part name="parameters" element="tns:ProcessMethod" />
</wsdl:message>
<wsdl:message name="CustomerService_ProcessMethod_OutputMessage">
<wsdl:part name="parameters" element="tns:ProcessMethodResponse" />
</wsdl:message>
>
<wsdl:portType name="CustomerService">
<wsdl:operation name="ProcessShipNotice">
<wsdl:input wsaw:Action=" http://mytargetNamespace/ServiceContract/ProcessMethod" message="tns:CustomerService_ProcessMethod_InputMessage" />
<wsdl:output wsaw:Action=" http://mytargetNamespace/ServiceContract/ProcessMethod" message="tns:CustomerService_ProcessMethod_OutputMessage" />
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
And the contract created
[ServiceContract]
public interface CustomerService
{
[System.ServiceModel.OperationContractAttribute(Action = "http://mytargetNamespace/ServiceContract/CustomerService/ProcessMethod”, ReplyAction = " http://mytargetNamespace/ServiceContract/CustomerService/ProcessMethodResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
void ProcessMethod(ProcessMethodRequest request);
I don't want to have ProcessMethod returned type void but rather ProcessMethodResponse type. How can I achieve it?
EDIT2: Here's my schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://myTargetNamespece/ServiceContract" elementFormDefault="qualified"
targetNamespace="http://myTargetNamespace/ServiceContract" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ProcessMethod">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="request" type="tns:ProcessMethodRequest" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ProcessMethodRequest" abstract="true" />
<xs:complexType name="ProcessMethodRequestWithPayload"/>
<xs:element name="ProcessMethodResponse">
<xs:complexType />
</xs:element>
</xs:schema>
Generated operation contract is correct. You WSDL specifies request/response operation (= two-way) with empty response. ProcessMethodResponse element is wrapper element for the response message but it does not contain any subelements = void response.
If you want to return ProcessMethodResponse you have to use message contracts. You can instruct svcutil to use message contracts by /mc or /messageContract switch.

svcutil soap fault namespace problem

I'm generating client side web service code using svcutil. The wsdl contract I'm using contains a soap fault. When the code is generated the fault seems to be wrapped in the namespace it was defined in the contract.
Can anyone explain why?
I'm simply running svcutil [filename]
Example WSDL:
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="HelloFault">
<s:complexType/>
</s:element>
<s:element name="HelloWorld">
<s:complexType/>
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld"/>
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse"/>
</wsdl:message>
<wsdl:message name="NewMessage">
<wsdl:part name="detail" element="tns:HelloFault"/>
</wsdl:message>
<wsdl:portType name="Service1Soap">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn"/>
<wsdl:output message="tns:HelloWorldSoapOut"/>
<wsdl:fault name="FaultName" message="tns:NewMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1Soap12" type="tns:Service1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://tempuri.org/HelloWorld" soapActionRequired="" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="FaultName">
<soap12:fault name="FaultName" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
Generates:
namespace tempuri.org
{
using System.Runtime.Serialization;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="HelloFault", Namespace="http://tempuri.org/")]
public partial class HelloFault : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
}
}
But other types declared in the contract are declared without a namespace?
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class HelloWorldRequest
{
...
You have to use the /UseSerializerForFaults attribute on svcutil, this will cause the XmlSerializer to be used for reading and writing faults (but only those), instead of the default DataContractSerializer (which will still be used for the rest of the stuff).
This seems to be a genuine bug - more info on my blog post.
I'm not sure I understand what the problem is... can you clarify?
From the looks of it, it would seem WCF is doing the right thing... the generated class has the right namespace URI in the [DataContract] attribute according to the schema in the WSDL fragment you showed.
What were you expecting?
Update: OK, I see what you're saying, but in this specific case, it's not unexpected either. If you look closely, notice that the other class you mention (HelloWorldRequest) is a Message Contract, not a DataContract. Message Contracts don't have namespaces themselves, though they can specify a namespace for the wrapper element around the message body (see the WrapperNamespace property).
In your case, the message contract specifies that it is not wrapped, so the WrapperNamespace wouldn't apply anyway.
Update #2: Regarding the CLR namespace (and not the XML namespace URI), SvcUtil does give you a way to control that; check out the /namespace: argument in the documentation.