C# SOAP Middleware MessageEncoder.WriteMessage - c#

I try to run this tutorial: custom-asp-net-core-middleware-example
But the reponse message at the client say´s:
S
ystem.ServiceModel.ProtocolException: There is a problem with the XML that was received from the network. See inner exception for more details.
---> System.Xml.XmlException: Name cannot begin with the '/' character, hexadecimal value 0x2F. Line 1, position 74.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, XmlException exception)
at System.Xml.XmlUTF8TextReader.VerifyNCName(String s)
at System.Xml.XmlUTF8TextReader.ReadQualifiedName(PrefixHandle prefix, StringHandle localName)
at System.Xml.XmlUTF8TextReader.ReadStartElement()
at System.Xml.XmlUTF8TextReader.Read()
at System.ServiceModel.Channels.Message.ReadStartBody(XmlDictionaryReader reader, EnvelopeVersion envelopeVersion, Boolean& isFault, Boolean& isEmpty)
at System.ServiceModel.Channels.ReceivedMessage.ReadStartBody(XmlDictionaryReader reader)
at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders, Boolean understoodHeadersModified)
at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
at System.ServiceModel.Channels.MessageEncoder.ReadMessageAsync(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType, CancellationToken cancellationToken)
at System.ServiceModel.Channels.HttpResponseMessageHelper.ReadChunkedBufferedMessageAsync(Task`1 inputStreamTask, TimeoutHelper timeoutHelper)
--- End of inner exception stack trace ---
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
I´ve also encounterd a problem with the request-message so I´ve written my own RequestMessage but I´m not sure whether I should write my own ResponseMessage, because I do not know how it should be.
Also I´ve changed the OperationDescription to fit the tutorials code, may there be the problem?
public OperationDescription(ContractDescription contract, MethodInfo operationMethod, OperationContractAttribute contractAttribute)
{
Contract = contract;
SoapAction = contractAttribute.Name ?? operationMethod.Name;
Name = contractAttribute.Action ?? $"{contract.Namespace.TrimEnd('/')}/{contract.Name}/{Name}".Trim('/');
IsOneWay = contractAttribute.IsOneWay;
ReplyAction = contractAttribute.ReplyAction;
DispatchMethod = operationMethod;
}

Related

Unterminated string. Expected delimiter converting byte[] to Json

I'm facing an awkward error with my app that I can't figure the reason...
The complete Stack Trace is this:
FALHA NO POST: ProcedimentosMidias :Unterminated string. Expected delimiter: ". Path '[12].ImageBytes', line 1, position 17190742. - em Newtonsoft.Json.JsonTextReader.ReadStringIntoBuffer(Char quote)
em Newtonsoft.Json.JsonTextReader.ReadAsBytes()
em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
em Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
em Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
em Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
em Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
em App_Services_ProcedimentosMidias.App_Services_ProcedimentosMidias_Load(Object sender, EventArgs e) na C:xxxxx.xxxxx.com.brapp_servicesProcedimentosMidias.aspx.vb:linha 48
The scenario is that the mobile app (Xamarin/C#) transmits some images/files serializing them to byte[] and placing in the model that is converted to JSON and transmitted via HTTP.
After that, the received byte[] is deserialized back to image/file.
The serialization code in the mobile app is this:
public static byte[] GetFileAsByteArray(string filePath)
{
if (System.IO.File.Exists(filePath))
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int bufferSize = 1024 * 1024;
FileInputStream fis = new FileInputStream(new File(filePath));
byte[] buffer = new byte[bufferSize];
int read = 0;
while((read = fis.Read(buffer)) > 0)
{
bos.Write(buffer, 0, read);
}
fis.Close();
return bos.ToByteArray();
}
else
{
return new byte[0];
}
//return System.IO.File.ReadAllBytes(filePath);
}
I place the byte[] from this method on an ImageByte[] variable on my model, that is converted to Json with Newtonsoft.Json package and transmitted via HTTP POST with Refit
The same user, also got this error that I guess is related
POST ProcedimentosMidias retornou um erro: Data.ExceptionSystem.AggregateException: One or more errors occurred. (Error while copying content to a stream.) -> System.Net.Http.HttpRequestException: Error while copying content to a stream. -> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. -> System.Net.Sockets.SocketException: Connection reset by peer - End of inner exception stack trace - at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.ThrowException (System.Net.Sockets.SocketError error) [0x00007] in <94ee25288e5b447880f446c994feac0b>:0 at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult (System.Int16 token) [0x0001f] in <94ee25288e5b447880f446c994feac0b>:0 at System.Threading.Tasks.ValueTask+ValueTaskSourceAsTask+<>c.<.cctor>b__4_0 (System.Object state) [0x00030] in <210883430b4a425fbc7186ded653500e>:0 - End of stack trace from previous location where exception was thrown - at Mono.Net.Security.MobileAuthenticatedStream.InnerWrite (System.Boolean sync, System.Threading.CancellationToken cancellationToken) [0x000d3] in <94ee25288e5b447880f446c994feac0b>:0 at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (System.Threading.CancellationToken cancellationToken) [0x00199] in <94ee25288e5b447880f446c994feac0b>:0 at Mono.Net.Security.AsyncProtocolRequest.StartOperation (System.Threading.CancellationToken cancellationToken) [0x0008b] in <94ee25288e5b447880f446c994feac0b>:0 at Mono.Net.Security.MobileAuthenticatedStream.StartOperation (Mono.Net.Security.MobileAuthenticatedStream+OperationType type, Mono.Net.Security.AsyncProtocolRequest asyncRequest, System.Threading.CancellationToken cancellationToken) [0x0024b] in <94ee25288e5b447880f446c994feac0b>:0 at System.Net.Http.HttpConnection.WriteAsync (System.ReadOnlyMemory`1[T] source) [0x0015d] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpContent.CopyToAsyncCore (System.Threading.Tasks.ValueTask copyTask) [0x00067] in <150dffdc6e124595ac779aab932eba71>:0 - End of inner exception stack trace - at System.Net.Http.HttpContent.CopyToAsyncCore (System.Threading.Tasks.ValueTask copyTask) [0x0008f] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnection.SendRequestContentAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpConnection+HttpContentWriteStream stream, System.Threading.CancellationToken cancellationToken) [0x000a0] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x012e6] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync (System.Net.Http.HttpConnection connection, System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0012b] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0014b] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ba] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <150dffdc6e124595ac779aab932eba71>:0 at Refit.RequestBuilderImplementation+<>c__DisplayClass23_0.b__0 (System.Net.Http.HttpClient client, System.Object[] paramList) [0x00173] in :0 - End of inner exception stack trace - -> (Inner Exception #0) System.Net.Http.HttpRequestException: Error while copying content to a stream. -> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. -> System.Net.Sockets.SocketException: Connection reset by peer - End of inner exception stack trace - at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.ThrowException (System.Net.Sockets.SocketError error) [0x00007] in <94ee25288e5b447880f446c994feac0b>:0 at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult (System.Int16 token) [0x0001f] in <94ee25288e5b447880f446c994feac0b>:0 at System.Threading.Tasks.ValueTask+ValueTaskSourceAsTask+<>c.<.cctor>b__4_0 (System.Object state) [0x00030] in <210883430b4a425fbc7186ded653500e>:0 - End of stack trace from previous location where exception was thrown - at Mono.Net.Security.MobileAuthenticatedStream.InnerWrite (System.Boolean sync, System.Threading.CancellationToken cancellationToken) [0x000d3] in <94ee25288e5b447880f446c994feac0b>:0 at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (System.Threading.CancellationToken cancellationToken) [0x00199] in <94ee25288e5b447880f446c994feac0b>:0 at Mono.Net.Security.AsyncProtocolRequest.StartOperation (System.Threading.CancellationToken cancellationToken) [0x0008b] in <94ee25288e5b447880f446c994feac0b>:0 at Mono.Net.Security.MobileAuthenticatedStream.StartOperation (Mono.Net.Security.MobileAuthenticatedStream+OperationType type, Mono.Net.Security.AsyncProtocolRequest asyncRequest, System.Threading.CancellationToken cancellationToken) [0x0024b] in <94ee25288e5b447880f446c994feac0b>:0 at System.Net.Http.HttpConnection.WriteAsync (System.ReadOnlyMemory`1[T] source) [0x0015d] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpContent.CopyToAsyncCore (System.Threading.Tasks.ValueTask copyTask) [0x00067] in <150dffdc6e124595ac779aab932eba71>:0 - End of inner exception stack trace - at System.Net.Http.HttpContent.CopyToAsyncCore (System.Threading.Tasks.ValueTask copyTask) [0x0008f] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnection.SendRequestContentAsync (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpConnection+HttpContentWriteStream stream, System.Threading.CancellationToken cancellationToken) [0x000a0] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x012e6] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync (System.Net.Http.HttpConnection connection, System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0012b] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0014b] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ba] in <150dffdc6e124595ac779aab932eba71>:0 at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <150dffdc6e124595ac779aab932eba71>:0 at Refit.RequestBuilderImplementation+<>c__DisplayClass23_0.b__0 (System.Net.Http.HttpClient client, System.Object[] paramList) [0x00173] in :0 <-
EDIT: This is the server side code, that converts the byte[] to image
Dim dataStream As System.IO.Stream = HttpContext.Current.Request.InputStream
Dim reader As New System.IO.StreamReader(dataStream)
Dim SyncData As New List(Of Procedimentosmidias.Procedimentosmidias)
SyncData = JsonConvert.DeserializeObject(Of List(Of Procedimentosmidias.Procedimentosmidias))(reader.ReadToEnd)
For Each item As Procedimentosmidias.Procedimentosmidias In SyncData
If Not xString.IsObjectNullOrEmpty(item.ImageBytes) Then
Dim caminho As String = Sys.AppClient.ClientAppFiles(item.ClientId.ToString) + "/" + Path.GetFileName(item.PathMidia)
EquinovetMobile.ConvertBytesToImageFile(item.ImageBytes, Server.MapPath(caminho))
item.PathMidia = ResolveUrl(caminho)
End If
Datapost.Mobile.InsertUpdateSync(userToken, tabela, item, "ProcedimentoMidiaId", item.ProcedimentoMidiaId.ToString())
Next
Public Shared Function ConvertBytesToImageFile(ByVal ImageData As Byte(), ByVal FilePath As String) As Boolean
If Not IsNothing(ImageData) Then
Dim fs As FileStream = New FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write)
Dim bw As BinaryWriter = New BinaryWriter(fs)
bw.Write(ImageData)
bw.Flush()
bw.Close()
fs.Close()
bw = Nothing
fs.Dispose()
ConvertBytesToImageFile = True
Else
ConvertBytesToImageFile = False
End If
End Function
Can you guys help me figure this out?
Thank you very much!

HttpClient has disconnected. Attempted to read past the end of the stream

I have a simple webApi app on IIS. There is a MessageController which is ControllerBase and [Route("api/[controller]"), ApiController]. There I have the only method [HttpPost] public IActionResult Send([FromBody] MessageViewModel message) with the model of two fields.
Then, I have an ApiConnector which sends messages to the webApi:
public class ApiConnector : IDisposable
{
private readonly HttpClient _client = new HttpClient();
private readonly string _apiUrl;
public ApiConnector(string apiUrl) => _apiUrl = apiUrl;
public void SendMessage(string sender, string message)
{
try
{
_client.PostAsJsonAsync($"{_apiUrl}/message", new { sender, message });
}
catch { }
}
}
Everything is written with Asp Core 2.2. When I run ApiConnector from ConsoleApp (inside of while(true) loop) everything is ok. When I POST from Postman everything is ok. But, as soon as I try to do the same from any other place (app, without endless loop, I suppose) a Controller of WebApi crushes.
Message: The client has disconnected;
Inner message: Attempted to read past the end of the stream.
How to send this request properly?
Exception text anyway:
"Message":"The client has disconnected",
"Data":{},
"InnerException":{
"ClassName":"System.IO.EndOfStreamException",
"Message":"Attempted to read past the end of the stream.",
"Data":null,
"InnerException":null,
"HelpURL":null,
"StackTraceString":null,
"RemoteStackTraceString":null,
"RemoteStackIndex":0,
"ExceptionMethod":null,
"HResult":-2147024858,
"Source":null,
"WatsonBuckets":null},
"StackTrace":"
at Microsoft.AspNetCore.Server.IIS.Core.IO.AsyncIOOperation.GetResult(Int16 token)\r\n
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadBody()\r\n
at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()\r\n
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)\r\n
at System.IO.Pipelines.Pipe.GetReadAsyncResult()\r\n
at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)\r\n
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory`1 memory, CancellationToken cancellationToken)\r\n
at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)\r\n
at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)\r\n
at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)\r\n
at Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter.ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)\r\n
at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.BindModelAsync(ModelBindingContext bindingContext)\r\n
at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()\r\n
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()\r\n
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()\r\n
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)\r\n
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)\r\n
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)\r\n
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()","HelpLink":null,"Source":"Microsoft.AspNetCore.Server.IIS","HResult":-2146232800
P.S. I have tried to Wait() _client's result to no avail.
I googled more accurate and found an issue. This is known problem and already fixed, but not in a current release. I suppose anyone who face such a problem need to build proper dlls mentioned in the issue discuss.

Resharper not debugging MSTest tests

I'm using Resharper Ultimate 2017.3.1
When I try to debug a unit tests
[DataTestMethod]
[DataRow("bla", "blub")]
public void Test_When_Then() { ... }
Then the test stops debugging, changes to state inconclusive and the following error is shown in the resharper test explorer window:
2018.01.17 13:02:20.367 ERROR Transition failed: Transition from state on event . Cause:
System.ArgumentException: There should be at least one test in the
test run. Parametername: tests --->
System.ServiceModel.FaultException: There should be at least one test
in the test run. Parametername: tests Server stack trace: at
System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime
operation, ProxyRpc& rpc) at
System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs, TimeSpan timeout) at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation) at
System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message) Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg) at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type) at
Microsoft.VisualStudio.TestPlatform.Core.ITestExecutorService.StartTestRun(IEnumerable1
tests, String testRunSettings, TestExecutionContext executionContext,
String dataCollectorServiceUri) at
JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.Wcf.TestExecutorServiceProxy.StartTestRun(IEnumerable1
tests, String testRunSettings, TestExecutionContext executionContext,
String dataCollectorServiceUri) --- End of inner exception stack trace
--- at JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.Wcf.TestExecutorServiceProxy.StartTestRun(IEnumerable1
tests, String testRunSettings, TestExecutionContext executionContext,
String dataCollectorServiceUri) at
JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.MsTestExecutionProtocol.StartTestRun()
at
Appccelerate.StateMachine.Machine.ActionHolders.ArgumentLessActionHolder.Execute(Object
argument) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\ActionHolders\ArgumentLessActionHolder.cs:line
37 at
Appccelerate.StateMachine.Machine.States.State2.ExecuteEntryAction(IActionHolder
actionHolder, ITransitionContext`2 context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
340
--- EXCEPTION #1/1 [LoggerException] Message = “ Transition failed: Transition from state on event .
Cause: System.ArgumentException: There should be at least one test in
the test run. Parametername: tests --->
System.ServiceModel.FaultException: There should be at least one test
in the test run. Parametername: tests
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime
operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins,
Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at Microsoft.VisualStudio.TestPlatform.Core.ITestExecutorService.StartTestRun(IEnumerable1
tests, String testRunSettings, TestExecutionContext executionContext,
String dataCollectorServiceUri)
at JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.Wcf.TestExecutorServiceProxy.StartTestRun(IEnumerable1
tests, String testRunSettings, TestExecutionContext executionContext,
String dataCollectorServiceUri)
--- End of inner exception stack trace ---
at JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.Wcf.TestExecutorServiceProxy.StartTestRun(IEnumerable1
tests, String testRunSettings, TestExecutionContext executionContext,
String dataCollectorServiceUri)
at JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.MsTestExecutionProtocol.StartTestRun()
at Appccelerate.StateMachine.Machine.ActionHolders.ArgumentLessActionHolder.Execute(Object
argument) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\ActionHolders\ArgumentLessActionHolder.cs:line
37
at Appccelerate.StateMachine.Machine.States.State2.ExecuteEntryAction(IActionHolder
actionHolder, ITransitionContext2 context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
340 ” ExceptionPath = Root ClassName = JetBrains.Util.LoggerException
HResult = COR_E_APPLICATION=80131600 StackTraceString = “ at
JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.MsTestExecutionProtocol.<.ctor>b__10(Object
sender, TransitionExceptionEventArgs2 args)
at Appccelerate.StateMachine.Machine.StateMachine2.RaiseEvent[T](EventHandler1
eventHandler, T arguments, ITransitionContext2 context, Boolean
raiseEventOnException) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\StateMachine.cs:line
404
at Appccelerate.StateMachine.Machine.StateMachine2.OnExceptionThrown(ITransitionContext2
context, Exception exception) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\StateMachine.cs:line
260
at Appccelerate.StateMachine.Machine.Contexts.TransitionContext2.OnExceptionThrown(Exception
exception) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\Contexts\TransitionContext.cs:line
74
at Appccelerate.StateMachine.Machine.States.State2.HandleException(Exception
exception, ITransitionContext2 context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
307
at Appccelerate.StateMachine.Machine.States.State2.HandleEntryActionException(ITransitionContext2
context, Exception exception) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
357
at Appccelerate.StateMachine.Machine.States.State2.ExecuteEntryAction(IActionHolder
actionHolder, ITransitionContext2 context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
345
at Appccelerate.StateMachine.Machine.States.State2.ExecuteEntryActions(ITransitionContext2
context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
330
at Appccelerate.StateMachine.Machine.States.State2.Entry(ITransitionContext2
context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
247
at Appccelerate.StateMachine.Machine.States.State2.EnterShallow(ITransitionContext2
context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
285
at Appccelerate.StateMachine.Machine.States.State2.EnterHistoryNone(ITransitionContext2
context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
429
at Appccelerate.StateMachine.Machine.States.State2.EnterByHistory(ITransitionContext2
context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
263
at Appccelerate.StateMachine.Machine.Transitions.Transition2.Fire(ITransitionContext2
context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\Transitions\Transition.cs:line
87
at Appccelerate.StateMachine.Machine.States.State2.Fire(ITransitionContext2
context) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\States\State.cs:line
222
at Appccelerate.StateMachine.Machine.StateMachine2.Fire(TEvent eventId, Object eventArgument) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\Machine\StateMachine.cs:line
230
at Appccelerate.StateMachine.PassiveStateMachine2.ProcessQueuedEvents()
in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\PassiveStateMachine.cs:line
339
at Appccelerate.StateMachine.PassiveStateMachine2.Execute() in C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\PassiveStateMachine.cs:line
324
at Appccelerate.StateMachine.PassiveStateMachine2.Fire(TEvent eventId, Object eventArgument) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\PassiveStateMachine.cs:line
177
at Appccelerate.StateMachine.PassiveStateMachine2.Fire(TEvent eventId) in
C:\projects\appccelerate\repos\statemachine\source\Appccelerate.StateMachine\PassiveStateMachine.cs:line
163
at JetBrains.ReSharper.UnitTesting.MSTest.Provider.Execution.Wcf.TestExecutorServiceClient.TestConnection(IEnumerable1
dummyTestResults)
at SyncInvokeTestConnection(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&
rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
at System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext
request, Boolean cleanThread, OperationContext
currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext
request, OperationContext currentOperationContext)
at System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult
result)
at System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult
result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult
result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceiveAsyncResult.OnReceive(IAsyncResult
result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult
result)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.SynchronizedMessageSource.ReceiveAsyncResult.OnReceiveComplete(Object
state)
at System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object
state)
at System.ServiceModel.Channels.StreamConnection.OnRead(IAsyncResult
result)
at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult
result)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Security.NegotiateStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count,
AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.ReadCallback(AsyncProtocolRequest
asyncRequest)
at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
at System.ServiceModel.Channels.ConnectionStream.IOAsyncResult.OnAsyncIOComplete(Object
state)
at System.ServiceModel.Channels.PipeConnection.OnAsyncReadComplete(Boolean
haveResult, Int32 error, Int32 numBytes)
at System.ServiceModel.Channels.OverlappedContext.CompleteCallback(UInt32
error, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32
error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) ”
Has anyone had this error too and knows how to fix it so that I can debug my unit tests again?
Thanks in advance
I had this error when updating ReSharper, it turned out to be a problem with the referenced NuGet packages related to Microsoft.VisualStudio.TestPlatform were outdated.
Create a new test project and compare the versions of these assemblies which will be added automatically when the project is created.
Using version 14.0.0.1 is working for me for the following assemblies:
ReSharper 2017.3.1
VS 2017 15.5.3

Error: Timeouts are not supported on this stream in Web Api

I have a api controller to recieve bunch of data from a webservice and translate it to a JSON.
When it fetches larger data pack, an error occures:
Timeouts are not supported on this stream
My controller is pretty simple:
public class ChangesPickupController : ApiController
{
[HttpPost]
public ChangeStructure[] GetChangesPickup(string id, int page, int toPage, UserInfoStructure uis)
{
var manager = new CkpClientManager();
try
{
var dt = DateTime.ParseExact(id, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
using (var client = manager.GetClient())
{
return client.GetChanges(uis, dt, page, toPage);
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
throw new Exception(ex.Message);
}
}
}
Do you have any clue, what might be a problem? Should I change some attributes for streaming somewhere or what?
Thanks in advance, JiKra
EDIT:
Well, here is my stack:
Server stack trace:
at System.IO.Stream.get_ReadTimeout()
at System.ServiceModel.Channels.DelegatingStream.get_ReadTimeout()
at System.ServiceModel.Channels.DelegatingStream.get_ReadTimeout()
at System.ServiceModel.Channels.HttpInput.WebResponseHttpInput.WebResponseInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.ServiceModel.Channels.MessageEncoder.BufferMessageStream(Stream stream, BufferManager bufferManager, Int32 maxBufferSize)
at System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType)
at System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at CkpSelfHost3.CkpWs.ICkpWS.GetChangesPickup(UserInfoStructure UserInfo, DateTime Datum, Int32 Strana, Int32 NaStranu)
at CkpSelfHost3.CkpWs.CkpWSClient.GetChangesPickup(UserInfoStructure UserInfo, DateTime Datum, Int32 Strana, Int32 NaStranu) in C:\Users\krakora\documents\visual studio 20
Host3\CkpSelfHost3\Service References\CkpWs\Reference.cs:line 2576
at CkpSelfHost3.Controllers.ChangesPickupController.GetChangesPickup(String id, Int32 page, Int32 toPage, UserInfoStructure uis) in C:\Users\krakora\documents\visual studio 2
fHost3\CkpSelfHost3\Controllers\ChangesPickupController.cs:line 30
Well, the problem was on the vendor's side in webservice provider.
JiKra

Error in deserializing body of reply message for operation

I'm writing console WCF-client for one WCF-WebService. When calling the service I get an error in deserializing body of request:
Error in deserializing body of reply message for operation 'GetProfiles'
Agent Code:
string userLogin = "root", userPassword = "root";
string ipaddress = "192.168.137.164";
HttpTransportBindingElement httpTransportBindingElement = new HttpTransportBindingElement();
httpTransportBindingElement.AuthenticationScheme = AuthenticationSchemes.Digest;
httpTransportBindingElement.KeepAliveEnabled = false;
httpTransportBindingElement.MaxBufferSize = int.MaxValue;
httpTransportBindingElement.MaxBufferPoolSize = int.MaxValue;
httpTransportBindingElement.MaxReceivedMessageSize = int.MaxValue;
TextMessageEncodingBindingElement textMessageEncodingBindingElement = new TextMessageEncodingBindingElement();
textMessageEncodingBindingElement.MaxReadPoolSize = int.MaxValue;
textMessageEncodingBindingElement.MaxWritePoolSize = int.MaxValue;
textMessageEncodingBindingElement.ReaderQuotas.MaxDepth = 64;
textMessageEncodingBindingElement.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
textMessageEncodingBindingElement.ReaderQuotas.MaxArrayLength = int.MaxValue;
textMessageEncodingBindingElement.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
textMessageEncodingBindingElement.ReaderQuotas.MaxStringContentLength = int.MaxValue;
CustomBinding binding = new CustomBinding(textMessageEncodingBindingElement, httpTransportBindingElement);
EndpointAddress MediaEndPointAddress = new EndpointAddress("http://" + ipaddress + ":80/onvif/services");
MediaClient mediaClient = new MediaClient(binding, MediaEndPointAddress);
mediaClient.ClientCredentials.UserName.UserName = userLogin;
mediaClient.ClientCredentials.UserName.Password = userPassword;
Profile[] profiles = mediaClient.GetProfiles(); // throw excpetion
I have already watched the requests and responses with a sniffer and it's OK! The WebService has sent '200 OK'. If I have a small response from the WebService, there won't be any errors and exceptions! I haven't got WebService code. What should I do?
Stack trace:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131075</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2012-01-11T11:11:12.2185609Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{550193ea-8569-40e6-b794-1a0eed69a1ba}" />
<Execution ProcessName="TestingConsole.vshost" ProcessID="6128" ThreadID="9" />
<Channel />
<Computer>WS-LSH</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/ru-RU/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
<Description>Throwing an exception.</Description>
<AppDomain>TestingConsole.vshost.exe</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Error in deserializing body of reply message for operation 'GetProfiles'. </Message>
<StackTrace>
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest)
at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at TestingConsole.Onvif.Media.Media.GetProfiles(GetProfilesRequest request)
at TestingConsole.Onvif.Media.MediaClient.TestingConsole.Onvif.Media.Media.GetProfiles(GetProfilesRequest request)
at TestingConsole.Onvif.Media.MediaClient.GetProfiles()
at TestingConsole.Program.Main(String[] args)
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
</StackTrace>
<ExceptionString>System.ServiceModel.CommunicationException: Error in deserializing body of reply message for operation 'GetProfiles'. ---> System.InvalidOperationException: There is an error in XML document (2, 6287). ---> System.Xml.XmlException: The byte 0x03 is not valid at this location. Line 2, position 6287.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlExceptionHelper.ThrowInvalidXml(XmlDictionaryReader reader, Byte b)
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlDictionaryReader.ReadString(Int32 maxStringContentLength)
at System.Xml.XmlDictionaryReader.ReadString()
at System.Xml.XmlBaseReader.ReadElementString()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read59_VideoSourceConfiguration(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read150_Profile(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read224_GetProfilesResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer73.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
--- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<ExceptionType>System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>There is an error in XML document (2, 6287).</Message>
<StackTrace>
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)
</StackTrace>
<ExceptionString>System.InvalidOperationException: There is an error in XML document (2, 6287). ---> System.Xml.XmlException: The byte 0x03 is not valid at this location. Line 2, position 6287.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlExceptionHelper.ThrowInvalidXml(XmlDictionaryReader reader, Byte b)
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlDictionaryReader.ReadString(Int32 maxStringContentLength)
at System.Xml.XmlDictionaryReader.ReadString()
at System.Xml.XmlBaseReader.ReadElementString()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read59_VideoSourceConfiguration(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read150_Profile(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read224_GetProfilesResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer73.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, XmlSerializer serializer, MessagePartDescription returnPart, MessagePartDescriptionCollection bodyParts, Object[] parameters, Boolean isRequest)</ExceptionString>
<InnerException>
<ExceptionType>System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The byte 0x03 is not valid at this location. Line 2, position 6287.</Message>
<StackTrace>
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlExceptionHelper.ThrowInvalidXml(XmlDictionaryReader reader, Byte b)
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlDictionaryReader.ReadString(Int32 maxStringContentLength)
at System.Xml.XmlDictionaryReader.ReadString()
at System.Xml.XmlBaseReader.ReadElementString()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read59_VideoSourceConfiguration(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read150_Profile(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read224_GetProfilesResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer73.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
</StackTrace>
<ExceptionString>System.Xml.XmlException: The byte 0x03 is not valid at this location. Line 2, position 6287.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlExceptionHelper.ThrowInvalidXml(XmlDictionaryReader reader, Byte b)
at System.Xml.XmlUTF8TextReader.Read()
at System.Xml.XmlDictionaryReader.ReadString(Int32 maxStringContentLength)
at System.Xml.XmlDictionaryReader.ReadString()
at System.Xml.XmlBaseReader.ReadElementString()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read59_VideoSourceConfiguration(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read150_Profile(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderMedia.Read224_GetProfilesResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer73.Deserialize(XmlSerializationReader reader)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)</ExceptionString>
</InnerException>
</InnerException>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
I rewrite my code. Now I have got:
string soapRequest = "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\">" +
"<s:Header>" +
"</s:Header>" +
"<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<GetProfiles xmlns=\"http://www.onvif.org/ver10/media/wsdl\"/>" +
"</s:Body>" +
"</s:Envelope>";
XmlReader envelopeReader = XmlReader.Create(new StringReader(soapRequest));
Message requestMsg = Message.CreateMessage(envelopeReader, int.MaxValue, MessageVersion.Soap12);
Message responseMsg = null;
IChannelFactory<IRequestChannel> channelFactory = binding.BuildChannelFactory<IRequestChannel>();
channelFactory.Open();
IRequestChannel channel = channelFactory.CreateChannel(MediaEndPointAddress);
channel.Open();
responseMsg = channel.Request(requestMsg);
Console.WriteLine(responseMsg.ToString());
The last string return message "Error reading body: System.Xml.XmlException: '�' contains invalid UTF8 bytes. ...}".
WebService sends non-ut8 bytes, but points "UTF-8" in header.
What can I do?
Reply Message Body
HTTP/1.1 200 OK
Server: gSOAP/2.7
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 11591
Connection: close
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:xmime5="http://www.w3.org/2005/05/xmlmime" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:ns1="http://www.onvif.org/ver20/analytics/wsdl" xmlns:ns2="http://www.onvif.org/ver10/schema" xmlns:ns3="http://docs.oasis-open.org/wsn/b-2" xmlns:ns4="http://docs.oasis-open.org/wsrf/bf-2" xmlns:ns5="http://docs.oasis-open.org/wsn/t-1" xmlns:ns6="http://www.onvif.org/ver10/device/wsdl" xmlns:ns7="http://www.onvif.org/ver10/events/wsdl" xmlns:ns9="http://docs.oasis-open.org/wsrf/r-2" xmlns:ns10="http://www.onvif.org/ver10/imaging/wsdl" xmlns:ns11="http://www.onvif.org/ver10/media/wsdl" xmlns:ns12="http://www.onvif.org/ver20/ptz/wsdl" xmlns:ns13="http://www.onvif.org/ver10/network/wsdl/" xmlns:ns14="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:ns16="http://www.onvif.org/ver10/analytics/wsdl/RuleEngineBinding" xmlns:ns17="http://www.onvif.org/ver10/analytics/wsdl/AnalyticsEngineBinding" xmlns:ns18="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:ns19="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:ns20="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:ns21="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:ns22="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:ns23="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:ns24="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:ns25="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:ns26="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding" xmlns:ns27="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding" xmlns:ns28="http://www.onvif.org/ver10/events/wsdl/EventPortType" xmlns:ns29="http://www.3svision.com.tw/2009/event/topics"> <SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body><ns11:GetProfilesResponse><ns11:Profiles token="Main_h264" fixed="true"><ns2:Name>Main h264</ns2:Name><ns2:VideoSourceConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken><Bounds xmlns="http://www.onvif.org/ver10/schema" height="720" width="1280" y="0" x="0"></Bounds></ns2:VideoSourceConfiguration><ns2:AudioSourceConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken></ns2:AudioSourceConfiguration><ns2:VideoEncoderConfiguration token="Main_h264"><ns2:Name>Main h264</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>H264</ns2:Encoding><ns2:Resolution><ns2:Width>1280</ns2:Width><ns2:Height>720</ns2:Height></ns2:Resolution><ns2:Quality>60</ns2:Quality><ns2:RateControl><ns2:FrameRateLimit>30</ns2:FrameRateLimit><ns2:EncodingInterval>15</ns2:EncodingInterval><ns2:BitrateLimit>3072</ns2:BitrateLimit></ns2:RateControl><ns2:H264><ns2:GovLength>0</ns2:GovLength><ns2:H264Profile>Baseline</ns2:H264Profile></ns2:H264><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:VideoEncoderConfiguration><ns2:AudioEncoderConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>G7Ю11</ns2:Encoding><ns2:Bitrate>64000</ns2:Bitrate><ns2:SampleRate>8000</ns2:SampleRate><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:AudioEncoderConfiguration></ns11:Profiles><ns11:Profiles token="Sub_h264" fixed="true"><ns2:Name>Sub h264</ns2:Name><ns2:VideoSourceConfiguration token="1"><ns2:Name>user1</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken><Bounds xmlns="http://www.onvif.org/ver10/schema" height="720" width="1280" y="0" x="0"></Bounds></ns2:VideoSourceConfiguration><ns2:AudioSourceConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken></ns2:AudioSourceConfiguration><ns2:VideoEncoderConfiguration token="Sub_h264"><ns2:Name>Sub h264</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>H264</ns2:Encoding><ns2:Resolution><ns2:Width>640</ns2:Width><ns2:Height>352</ns2:Height></ns2:Resolution><ns2:Quality>70</ns2:Quality><ns2:RateControl><ns2:FrameRateLimit>30</ns2:FrameRateLimit><ns2:EncodingInterval>15</ns2:EncodingInterval><ns2:BitrateLimit>3072</ns2:BitrateLimit></ns2:RateControl><ns2:H264><ns2:GovLength>0</ns2:GovLength><ns2:H264Profile>Baseline</ns2:H264Profile></ns2:H264><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:VideoEncoderConfiguration><ns2:AudioEncoderConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>G711</ns2:Encoding><ns2:Bitrate>64000</ns2:Bitrate><ns2:SampleRate>8000</ns2:SampleRate><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:AudioEncoderConfiguration></ns11:Profiles><ns11:Profiles token="Motion_jpeg" fixed="true"><ns2:Name>Motion jpeg</ns2:Name><ns2:VideoSourceConfiguration token="2"><ns2:Name>user2</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken><Bounds xmlns="http://www.onvif.org/ver10/schema" height="720" width="1280" y="0" x="0"></Bounds></ns2:VideoSourceConfiguration><ns2:AudioSourceConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken></ns2:AudioSourceConfiguration><ns2:VideoEncoderConfiguration token="Motion_jpeg"><ns2:Name>Motion jpeg</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>JPEG</ns2:Encoding><ns2:Resolution><ns2:Width>1280</ns2:Width><ns2:Height>720</ns2:Height></ns2:Resolution><ns2:QualitЭy>70</ns2:Quality><ns2:RateControl><ns2:FrameRateLimit>15</ns2:FrameRateLimit><ns2:EncodingInterval>15</ns2:EncodingInterval><ns2:BitrateLimit>3072</ns2:BitrateLimit></ns2:RateControl><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:VideoEncoderConfiguration><ns2:AudioEncoderConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>G711</ns2:Encoding><ns2:Bitrate>64000</ns2:Bitrate><ns2:SampleRate>8000</ns2:SampleRate><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:AudioEncoderConfiguration></ns11:Profiles><ns11:Profiles token="mc_test" fixed="false"><ns2:Name>mc_test</ns2:Name><ns2:VideoSourceConfiguration token="2"><ns2:Name>Hе</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken><Bounds xmlns="http://www.onvif.org/ver10/schema" height="720" width="1280" y="0" x="0"></Bounds></ns2:VideoSourceConfiguration><ns2:AudioSourceConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken></ns2:AudioSourceConfiguration><ns2:VideoEncoderConfiguration token="Motion_jpeg"><ns2:Name>јч
#јч
#peg</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>JPEG</ns2:Encoding><ns2:Resolution><ns2:Width>1280</ns2:Width><ns2:Height>720</ns2:Height></ns2:Resolution><ns2:Quality>70</ns2:Quality><ns2:RateControl><ns2:FrameRateLimit>15</ns2:FrameRateLimit><ns2:EncodingInterval>15</ns2:EncodingInterval><ns2:BitrateLimit>3072</ns2:BitrateLimit></ns2:RateControl><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:VideoEncoderConfiguration><ns2:AudioEncoderConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>G711</ns2:Encoding><ns2:Bitrate>64000</ns2:Bitrate><ns2:SampleRate>8000</ns2:SampleRate><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:AudioEncoderConfiguration></ns11:Profiles><ns11:Profiles token="MACROSCOP" fixed="false"><ns2:Name>MACROSCOP</ns2:Name><ns2:VideoSourceConfiguration token="2"><ns2:Name>Hе</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken><Bounds xmlns="http://www.onvif.org/ver10/schema" heightЮ="720" width="1280" y="0" x="0"></Bounds></ns2:VideoSourceConfiguration><ns2:AudioSourceConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:SourceToken>0</ns2:SourceToken></ns2:AudioSourceConfiguration><ns2:VideoEncoderConfiguration token="Motion_jpeg"><ns2:Name>јч
#јч
#peg</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>JPEG</ns2:Encoding><ns2:Resolution><ns2:Width>1280</ns2:Width><ns2:Height>720</ns2:Height></ns2:Resolution><ns2:Quality>70</ns2:Quality><ns2:RateControl><ns2:FrameRateLimit>15</ns2:FrameRateLimit><ns2:EncodingInterval>15</ns2:EncodingInterval><ns2:BitrateLimit>3072</ns2:BitrateLimit></ns2:RateControl><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:VideoEncoderConfiguration><ns2:AudioEncoderConfiguration token="0"><ns2:Name>user0</ns2:Name><ns2:UseCount>0</ns2:UseCount><ns2:Encoding>G711</ns2:Encoding><ns2:Bitrate>64000</ns2:Bitrate><ns2:SampleRate>8000</ns2:SampleRate><ns2:Multicast><ns2:Address><ns2:Type>IPv4</ns2:Type><ns2:IPv4Address>0.0.0.0</ns2:IPv4Address></ns2:Address><ns2:Port>0</ns2:Port><ns2:TTL>5</ns2:TTL><ns2:AutoStart>false</ns2:AutoStart></ns2:Multicast><ns2:SessionTimeout>PT0S</ns2:SessionTimeout></ns2:AudioEncoderConfiguration></ns11:Profiles></ns11:GetProfilesResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
At first, if Profile class is yourth, check the contract of your Profile object - maybe it hasn't well-configured DataContract attributes. If you have dll with Profile class, provided by the service owner, maybe it is of wrong version. YOu can try enabling WCF trace and compare caught XML with contract of Profile object (use dotPeek or any other decompiler to get class code from dll)
If the response from the web serivce is 200 OK in your sniffer and is failing in your client with the above exception then its worth trying to update your proxy. There might be a situation that the wsdl has changed and the response object being recieved is not in teh expected format on your client side

Categories