I am consuming a WCF in a classLibrary by adding a web reference of the WCF service.
All the classes of service are showing, their is no build error.
But when calling the method of service, getting the below mentioned error:-
And I am passing a object in the method which contains the xml.
But when I am making a proxy class by using svcutil.exe ,then call the method of service with the same object having same xml no error is coming, it is working fine.
_**It means that in classLibrary we can consume a WCF service only by creating a proxy not by adding the web reference of the WCF service.
Is the above statement is correct or not?
If not then please provide a solution for it.**_
**Error:
System.InvalidOperationException: There is an error in XML document (1, 528). ---> System.InvalidOperationException: Instance validation error: '' is not a valid value for PropertySubType.
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read29_PropertySubType(String s)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read30_Hotel(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read31_SearchResult(Boolean isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderHotelFlow.Read100_SearchHotelsResponse()
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer8.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.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at ClassLibTestTouricoWCFinCsharp.com.touricoholidays.demo2.HotelFlow.SearchHotels(SearchRequest request) in C:\Documents and Settings\Prakash.singh\My Documents\Visual Studio 2005\Projects\ClassLibTestTouricoWCFinCsharp\ClassLibTestTouricoWCFinCsharp\Web References\com.touricoholidays.demo2\Reference.cs:line 132
at ClassLibTestTouricoWCFinCsharp.Class1.test() in C:\Documents and Settings\Prakash.singh\My Documents\Visual Studio 2005\Projects\ClassLibTestTouricoWCFinCsharp\ClassLibTestTouricoWCFinCsharp\Class1.cs:line 78**
You're basically seeing the difference between a Service Reference and a Web Reference. What it sounds like is that the WCF service you are consuming is not compatible with adding a web reference, and you should instead use the service reference.
Having said that, it's much cleaner to not use either, and instead use a ChannelFactory or create your own proxy by deriving from ClientBase. Here is an example of using a ChannelFactory.
ChannelFactory<IContract> factory = new ChannelFactory<IContract>("BindingConfigName");
IContract channel = factory.CreateChannel();
channel.YourOperation();
((ICommunicationObject)channel).Close();
Related
Any help appreciated.
The error message reads:
System.UriFormatException: Invalid URI: The format of the URI could not be determined. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at System.Web.Services.Protocols.WebClientProtocol.set_Url(String value) at WebApplication1.Chase.pconWSService.set_Url(String Value) in \Visual Studio 2008\Projects\WebApplication1\WebApplication1\Web References\Chase\Reference.vb:line 102 at WebApplication1.Chase.pconWSService..ctor() in \Visual Studio 2008\Projects\WebApplication1\WebApplication1\Web References\Chase\Reference.vb:line 83
But is this referring to the web reference (wsdl)? And why 2 different locations?
The wsdl was given to me by the vendor, anyway here is my code, it's short:
Protected Sub transfer()
Try
Dim objXMLHTTP As New MSXML2.ServerXMLHTTP60()
Dim service As New Chase.pconWSService ' The error is thrown here
The problem was my web config was not pointed at the actual web service (host) but at my local machine. Once I repointed it the thing worked.
I have 2 pages in sitefinity (w/MVC) that have different controllers with identical parameters. One returns a page with search results and all the form elements to conduct that search.
I would like a 'print' button on that first form to send all the form fields to a different page, with a different controller/component with the same parameters.
(I have posted the same question on Sitefinity's forums, but have not yet received a response. I have also been searching for this, but not finding similar results)
In ASP.Net, or Actual MVC, this would work easily.
In MVC I was able to do it like this:
var d = document;
var f = d.forms[0];
window.open('', 'B2BDownload', 'width=900,height=800,resizable,scrollbars;');
var pt = f.target;
var pm = f.action;
f.action = '/UtilityPages/DownloadInvoices';
f.target = 'B2BDownload';
f.submit();
f.action = pm;
f.target = pt;
but in Sitefinity's MVC that same code produces this error: (at the correct page)
Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
Source Error:
[No relevant source lines]
Source File: c:\Users\dsagmi\AppData\Local\Temp\Temporary ASP.NET Files\root\e2f026a5\8dd189ac\App_Web_15de2cba-1969-6a7f-bafc-ff00004b1c1a_20t98b8c6261_dealerportal_en.aspx.d63928b6.zmrfaltr.0.cs Line: 0
Stack Trace:
[ViewStateException: Invalid viewstate.
Client IP: ::1
Port: 41710
Referer: http://localhost:60876/history/order-invoice-history
Path: /UtilityPages/PrintInvoices
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36
ViewState: /wEPDwULLTE1NDc5NTk3MzZkZEkHl7CSK6SqsTcfmGWe//o1dcqh]
[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +198
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +432
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +8
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
System.Web.UI.HiddenFieldPageStatePersister.Load() +248
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +88
System.Web.UI.Page.LoadAllState() +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
System.Web.UI.Page.ProcessRequest() +72
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +58
ASP.sfpageservice_15de2cba_1969_6a7f_bafc_ff00004b1c1a_20t98b8c6261_dealerportal_en_aspx.ProcessRequest(HttpContext context) in c:\Users\dsagmi\AppData\Local\Temp\Temporary ASP.NET Files\root\e2f026a5\8dd189ac\App_Web_15de2cba-1969-6a7f-bafc-ff00004b1c1a_20t98b8c6261_dealerportal_en.aspx.d63928b6.zmrfaltr.0.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408
This occurs because the page contains view state, and view state is only decipherable by the page which generated it. The target page is trying to decipher this field, but it can't and is instead throwing an exception.
Immediately before the call to submit(), try searching the DOM for the hidden form field named "__VIEWSTATE" and set its value to the empty string (""). This will cause the destination page not to try to load view state.
I have web services written on WCF. I use request/response pattern and don't use FaultException. I return an error code in response contract as string. I need to expose error codes for clients in order to clients can handle exceptions.
For example:
Var r = client.DoSomething();
Switch (r.ErrorCode)
{
Case ERROR_CODES.SomeCode:
//TODO:
}
Clients are WS-*, not only .Net.
UPDATE:
Sorry, my English is elementary. I've tried to explain in a different way.
When I use class File, I know that this class can throws some exceptions, for example, FileNotFoundException or DirectoryNotFoundException. If I create a File service How can I tell client that my service can returns "FileNotFound" or other error codes?
We generally try and use FaultContracts.
When we cannot we use a Response object that inherits from ResponseBase. ResponseBase has 2 properties, StatusCode and StatusMessage.
In your case ErrorCode, just add this property to your data contract.
I experience a weird behavior when accessing my web services into a web browser and it leads to an exception while generating.
Here is my scenario:
Access web page: http://localhost:10100/WCFService1.svc?wsdl
Access web page: http://localhost:10100/WCFService2.svc?wsdl
The problem is that the output of WCFService2.svc WSDL contains all the definition of WCFService1 merged with WCFService2.
Furthermore, when I access another WSDL which contains a method having the same name of previously generated WSDL, I get this exception (surely because my WSDL are being merged together).
I also notice the name of the contract is kind of weird having the ":" before the service name: http://MyCompany.ca/:IWCFService3
Someone have a clue what is going on with the "WSDL export extension"?
An ExceptionDetail, likely created by
IncludeExceptionDetailInFaults=true,
whose value is:
System.InvalidOperationException: An exception was thrown in a call to a
WSDL export extension:
System.ServiceModel.Description.DataContractSerializerOperationBehavior
contract: http://MyCompany.ca/:IWCFService3
----> System.InvalidOperationException: The
MyCompany.IWCFService3.Import
operation references a message element
[http://MyCompany.ca/:Import] that has
already been exported from the
MyCompany.IWCFService2.Import
operation. You can change the name of
one of the operations by changing the
method name or using the Name property
of OperationContractAttribute.
Alternatively, you can control the
element name in greater detail using
the MessageContract programming model.
at System.ServiceModel.Description.MessageContractExporter.AddElementToSchema(XmlSchemaElement
element, String elementNs,
XmlSchemaSet schemaSet)
at System.ServiceModel.Description.MessageContractExporter.ExportWrappedPart(Message
message, String elementName, String
elementNs, XmlSchemaSet schemaSet,
Boolean skipSchemaExport)
at System.ServiceModel.Description.DataContractSerializerMessageContractExporter.ExportBody(Int32
messageIndex, Object state)
at System.ServiceModel.Description.MessageContractExporter.ExportMessage(Int32
messageIndex, Object state)
at System.ServiceModel.Description.MessageContractExporter.ExportMessageContract()
at System.ServiceModel.Description.DataContractSerializerOperationBehavior.System.ServiceModel.Description.IWsdlExportExtension.ExportContract(WsdlExporter
exporter,
WsdlContractConversionContext
contractContext)
at System.ServiceModel.Description.WsdlExporter.CallExtension(WsdlContractConversionContext
contractContext, IWsdlExportExtension
extension)
I found my problem: We have a huge set of Web Services and we were having a single instance of System.ServiceModel.Description.ServiceMetadataBehavior that we were sharing among all the services. Making a new instance of ServiceMetadataBehavior for each service fixed the issue.
I have written a one-way service in php that contains one method with OperationContract( IsOneWay=true)
When I call this method from my .net client application then it gives me an error
The one-way operation returned a
non-null message with Action=''
Here is my proxy generated method :
[OperationContractAttribute(IsOneWay = true, Action = "http://192.168.1.5/zfsapi/api.php#terminateProcess")]
[XmlSerializerFormatAttribute(Style=OperationFormatStyle.Rpc, SupportFaults=true, Use=OperationFormatUse.Encoded)]
[ServiceKnownTypeAttribute(typeof(ZfsSnapshot))]
void terminateProcess(int pid);
Can anyone tell me why this error occur and solution on this?