dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.72k stars 558 forks source link

Add Mtom support in WCF runtime #1810

Closed chris5287 closed 3 years ago

chris5287 commented 7 years ago

I am getting the following error when using the Visual Studio WCF Connected Service extension for Visual Studio 2017:

Scaffolding Code ...
Error:Warning: The following Policy Assertions were not Imported:   XPath://wsdl:definitions[@targetNamespace='http://imaging.oracle/']/wsdl:binding[@name='DocumentContentServicePortBinding']
  Assertions:
    <ns1:OptimizedMimeSerialization xmlns:ns1='http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization'>..</ns1:OptimizedMimeSerialization>
Warning: Unsupported binding element type: 'System.ServiceModel.Channels.UnrecognizedAssertionsBindingElement'.
Warning: Unsupported message encoding element type: 'System.ServiceModel.Channels.MtomMessageEncodingBindingElement'. It must be one of the following types: 'System.ServiceModel.Channels.BinaryMessageEncodingBindingElement', 'System.ServiceModel.Channels.TextMessageEncodingBindingElement.'
Warning: Endpoint 'DocumentContentServicePort' at address 'http://localhost/imaging/ws/DocumentContentService' contains one or more bindings not compatible with .Net Core apps, skipping...
Error: No endpoints compatible with .Net Core apps were found.
Failed to generate service reference.

The WSDL/XSD file causing the issue: DocumentContentService.xsd.txt DocumentContentService.wsdl.txt

dotnet --info

.NET Command Line Tools (1.0.0)

Product Information:
 Version:            1.0.0
 Commit SHA-1 hash:  e53429feb4

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0
JoaoSaDevdotNet commented 2 years ago

stream.Seek(0, SeekOrigin.Begin); using var reader = XmlDictionaryReader.CreateMtomReader(stream, Encoding.UTF8, XmlDictionaryReaderQuotas.Max); var doc = new XmlDocument(); doc.Load(reader); return doc;

I tried to use your solution but I am getting the error The expected encoding 'utf-16LE' does not match the actual encoding 'utf-16BE'. Do you know what means? I can't be able to found nothing about it.

JoaoSaDevdotNet commented 2 years ago

@JoaoSaDevdotNet what do you need fixed? It's very hard to help you based on that kind of error description.

Do you have an actual code sample? Maybe with a list of referenced NuGet packages and their versions?

Then somebody may be able to tell you what the problem is. 👍

Okay follow the code

using var mtomMessageInMemory = new MemoryStream(xml); var dataSerializer = new DataContractSerializer(typeof(ReturningType));

Here I get the error I said var reader = XmlDictionaryReader.CreateMtomReader(mtomMessageInMemory, Encoding.UTF8, lDictionaryReaderQuotas.Max);

return (ReturningType)dataSerializer.ReadObject(reader);

mconnew commented 2 years ago

@JoaoSaDevdotNet , try replacing Encoding.UTF8 with Encoding.BigEndianUnicode

jhowfaithluby commented 2 years ago

Hello @mconnew , I tried this solution proposed in the answers: https://github.com/dotnet/wcf/issues/1810#issuecomment-963604841 but without success, the same error reading not supported. I'm using webapi .netcore 6 is there any way to do it without needing a wcf?

Homaks commented 1 year ago

Hello, @mconnew Simple answer to your question (https://github.com/dotnet/wcf/issues/1810#issuecomment-963604841): legacy or some not standard soap services (( Please make a class XmlMtomReader public. You will make a lot of people happy )