Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all 555 articles
Browse latest View live

wsdl question

$
0
0

When I add a service reference this generates classes for the service that I can use to call the service.

I'm assuming that VS uses the WSDL returned from the hosted service to generate the classes I need. I don't think the physical wsdl is stored in my client application after I add the service reference because the physical wsdl is only needed to generate the classes. Is this correct?

Also, is it correct to say that the host service generates wsdl only as requested by client applications? i.e. VS doesn't generate wsdl when compiling the service or in any other scenario except when requested by a client application? Are you familiar with the particular process that accepts the wsdl request, generates the wsdl and returns it?


Creating background thread(expected to work till service life cycle) on Application start with IIS hosted WCF service

$
0
0

Hi, 

I am hosting a wcf service in IIS which provides necessary GUI interaction with data/MQ messaging, along with this I want one more thread to keep running for the complete life cycle of service. Job of this thread will be to see for any new message in MQ or look for any updates in database at certain time intervals and update local cache => static List<obj>, local cache will be used by WCF service based on client requests.

Steps :

1) Created WCF service, instance context Singleton, concurency Multiple.

2) On application start created and started a thread which polls MQ irrespective of any user request to service.

I have been able to do this, everything goes well for 30-40 minutes sometimes 2-3 hours with all the service and background threads running in parallel.(WCF request threads and back ground thread) -->I see logs wid different thread id whcih I am printing, based on that I am quoting this.

After a while at any anonymous point the background thread disappears from logs and I dont see any activity on that. During this my WCF service does not go down it still process user reuests from UI, only my background thread does not seem to be alive.

Everytime the background thread disappears at differnt point, there is no consistancy or pattern observed.

When my background thread disappears service does not go on app_error. I have even put try catch when I am starting a thread on app_start, it also does not catch anything. I also does not have any empty catch block which could be possibly catching any unhadled excpetion causing thread abort. I am unable to find what could be happening, is there a possiblity that app pool is killing the thread or anything like that ?

What I understnad is My Service is totally independent of the thread which I have created on Application_start.

Can someone please suggest/guide what could be happening ?

trying to write a basic rest wcf service

$
0
0

Hello - I'm trying to write a basic rest wcf service. The following url made the task sound simple enough: http://msdn.microsoft.com/en-us/magazine/dd315413.aspx#id0070034

The wcf service is working as a standard wcf service. I'm able to create a client proxy and call the svc GetCustomer method to return a Customer object. Based on the info url I referenced in my post above it appears that all I need to do to make my RestTest.GetCustomer(int id) REST-ful is to add the following attribute at the top: [WebGet(UriTemplate = "/{id}")]

Then I added the following endpoint to the Web.config of the service project to enable REST (weHttpBinding):

<service name="RestTest">
<endpoint address="RestTest.svc" binding="webHttpBinding" contract="IRestTest" />
</service>

After I do that then shouldn't I just be able to call the wcf svc through a url like this?: http://localhost:81/RestTest.svc/1

When I try to call the svc like this I get a 404 error. What am I missing here?

how to handle int id param in wcf rest services?

$
0
0

Hello - I'd like to return a Customer object from a WCF REST method based on customer ID.  For example: http://localhost/RestTest.svc/Customers/123

I can successfully use the following OperationContract to do this:

[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Customers/{id}")]
Customer GetCustomer(string id);

I'd rather use an int id parameter instead of string id parameter but I think this may be a constraint of WCF REST services.

Am I stuck with a string id parameter or is there a workaround that will let me define the id parameter as an int?

how to save an object with wcf rest?

$
0
0

Hello - I'm able to use the following code as an interface to allow my REST service to return a Customer object based on an ID parameter:

[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Customers/{id}")]
Customer GetCustomer(string id);

Now I need to write an interface to allow my REST service to save a Customer object based on some Customer object XML.  Can you show me how I should put together that interface?

generic xml/json rest wcf service

$
0
0

Hello - I read the following information online:

"The trick to getting the method to respond with and to either XML or JSON is all in the request headers. To tell the service you want to work with XML, set both the HTTP Accept and Content-Type headers to "application/xml". Then if you post XML, it will be deserialized and the return object will be serialized into XML. If you want JSON, set both to "application/json"

In concept this seems like a good way for WCF REST services to be generic enough to support SOAP and JSON communication with a single method. Is this the recommended way to provide WCF REST services these days?

I was able to set the Content-Type request header to application/xml to communicate with the WCF REST service via XML.  Then I was able to set the Content-Type request header to application/json to communicate with the WCF REST service via JSON. However, although my request was received in JSON my response was returned in XML. What do I need to change to ensure the WCF REST service returns its response as JSON in this scenario?

The maximum string content length quota (8192) has been exceeded while reading XML data

$
0
0

Hello,

I'm in trouble with wcf hosted on Windows Azure as a web service. This error occurs when I send a lot of string (>10kb) to the service.

Error message:

The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader

I tried to re-configure the config.dll.client to increase the readerQuotas but it wont work:

<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

Please help me

How to Deserialize an XML String Variable

$
0
0

I need to extract XML data from the National Weather Service’s Web Service.  It returns XML data as a text string.  I’m looking for the best way to get values of elements and attributes from specific nodes. The code below throws this error on the last line:

System.InvalidOperationException: <dwml xmlns=''> was not expected.

 

            // Get weather forecast
            string strWxXml = "";

            gov.weather.graphical.weatherParametersType paramsWX = new detailwindow.gov.weather.graphical.weatherParametersType();
            paramsWX.wx = true;
            gov.weather.graphical.ndfdXML xmlWx = new detailwindow.gov.weather.graphical.ndfdXML();
            DateTime dtStart = DateTime.Now;
            DateTime dtEnd = DateTime.Now.AddDays(5.00);
            Decimal longitude = 39.73M;
            Decimal latitude = -86.27M;

            // Call web service proxy class
            strWxXml = xmlWx.NDFDgen(longitude, latitude, 0, dtStart, dtEnd, 0, paramsWX);

            DataSet dsXML = new DataSet();
            System.IO.StringReader read = new StringReader(strWxXml);
            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(dsXML.GetType());
            System.Xml.XmlReader reader = new XmlTextReader(read);

            dsXML = (DataSet)serializer.Deserialize(reader);

I have also tried adding this above the partial class statement:

[Serializable, System.Xml.Serialization.XmlRoot("dwml")]

 


WCF supports by Inernet Explorer

$
0
0

Hi,

I listen from some one WCF runs properly only Inernet Explorer instead of FireFox, Chrome & opera .....

Please conform

Furthermore i notice that some tags values not load in firefox and chrome while internet explorer show xml correctly

<Employee xmlns="www.soap-enveloper.com">

The "xmlns="www.soap-enveloper.com" not show in firefox and chrome, but perfectly on Internet Explorer

Thank you

Servie code file methods values in WSDL

$
0
0

Hi i have a service in WCF name Service1 contains Service1.svc, Service1.cs, IService1.cs

IService1.cs

using System;
using System.ServiceModel;
using System.Data;

[ServiceContract]
public interface IService
{
	[OperationContract]
    DataTable DoWork();
}

Service1.cs

using System;
using System.ServiceModel;
using System.Data;

public class Service : IService
{
	public DataTable DoWork()
	{
        DataTable dt = new DataTable();
        dt.Columns.Add("Name");
        dt.Columns.Add("Age");
        dt.Columns.Add("Desg");

        for (int i = 0; i <= 3; i++)
        {
            DataRow dr = dt.NewRow();
            dr["Name"] = "Taha" + i;
            dr["Age"] = "" + i;
            dr["Desg"] = "" + i;
            dt.Rows.Add(dr);
        }
        dt.AcceptChanges();
        return dt;
	}
}

For view the information i need to must create a client there is any another way (May be in WSDL) that i see the DataTable information which define in service.cs file

Thank you

Furthermore i set the breakpoint in service.cs file should debugging comes here...

rest - idempotence

$
0
0

Hello - I've seen the concept of "idempotence" referred to while researching WCF REST services.

Can someone please explain the concept of idempotence and its relationship to WCF REST services?

File Upload in WCF using jquery

$
0
0

Hi i need samples to upload files in WCF using jquery concept without postback.I should open and read the file by using FileStream concept.Can anyone helpout.

Create Service using WSDL

$
0
0

Hi

I want to ask that should we create a service using a WSDL file, than how....

Thank You

create service skelton from WSDL file

$
0
0

Hi i want to know how the skelton of Service created from a WSDL file

for example i have a created a simple WCF Service

IService.cs

using System;
using System.Data;
using System.ServiceModel;

[ServiceContract]
public interface IService
{
	[OperationContract]
	DataTable DoWork();
}

Service.cs

using System;
using System.Data;
using System.ServiceModel;

public class Service : IService
{
	public DataTable DoWork()
	{
        DataTable dt = new DataTable();
        DataRow dr = dt.NewRow();
        dr["Name"] = "Tza";
        dt.Rows.Add(dr);
        dt.AcceptChanges();
        return dt;
	}
}

Above service returns me the url: http://localhost/TestWCFService1/Service.svc?wsdl

For create skelton i try the command svcutil http://localhost/TestWCFService1/Service.svc?wsdl which returns me a service.cs and output.config file

using System.Data;

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="IService")]
public interface IService
{
    
    // CODEGEN: Parameter 'DoWorkResult' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService/DoWork", ReplyAction="http://tempuri.org/IService/DoWorkResponse")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    DoWorkResponse DoWork(DoWorkRequest request);
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="DoWork", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class DoWorkRequest
{
    
    public DoWorkRequest()
    {
    }
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="DoWorkResponse", WrapperNamespace="http://tempuri.org/", IsWrapped=true)]
public partial class DoWorkResponse
{
    
    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
    [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
    public System.Data.DataTable DoWorkResult;
    
    public DoWorkResponse()
    {
    }
    
    public DoWorkResponse(System.Data.DataTable DoWorkResult)
    {
        this.DoWorkResult = DoWorkResult;
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IServiceChannel : IService, System.ServiceModel.IClientChannel
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class ServiceClient : System.ServiceModel.ClientBase<IService>, IService
{
    
    public ServiceClient()
    {
    }
    
    public ServiceClient(string endpointConfigurationName) : 
            base(endpointConfigurationName)
    {
    }
    
    public ServiceClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }
    
    public ServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }
    
    public ServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress)
    {
    }
    
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    DoWorkResponse IService.DoWork(DoWorkRequest request)
    {
        return base.Channel.DoWork(request);
    }
    
    public System.Data.DataTable DoWork()
    {
        DoWorkRequest inValue = new DoWorkRequest();
        DoWorkResponse retVal = ((IService)(this)).DoWork(inValue);
        return retVal.DoWorkResult;
    }
}



which is the skelton file for service if i am not wrong, but i dont know how do i create a skelton with above file which returns to me by svcutil command

orignal file contains simple neet and clean code but the code provide by svcutil is very long, i unable to understand

Please advice how i create a skelton from wsdl file

Thank you

SOAP envelope request and get respose using c#

$
0
0

I have third party company given us URL and SOAP envelop format , now I need to request i have used below method but gives me errors.

I have string soapenv =

 HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://thirdparycompanydom.com/");
                req.Headers.Add("SOAPAction", "\"http://tempuri.org/Register\"");
                req.ContentType = "text/xml; charset=\"utf-8\"";
                req.Accept = "text/xml";
                req.Method = "POST";

                using (Stream stm = req.GetRequestStream())
                {
                    using (StreamWriter stmw = new StreamWriter(stm))
                    {
                        stmw.Write(soapenv);
                    }
                }

                WebResponse response = req.GetResponse();
               
                StreamReader responseStream =new  StreamReader(response.GetResponseStream());
                lbl.Text = responseStream.ReadToEnd();
                responseStream.Close();


this gives me error

System.Net.WebException: The remote server returned an error: (500) Internal Server Error

what it could be, do you think my code have erros


Get ip address

$
0
0

Hi, 

I will like to get the ip adress of my computer such as (220.255.1.46) so I can get the country I am at. But I keep getting ::1 as the output.

This is what i used: 

Request.ServerVariables["REMOTE_ADDR"];

What is my problem? 

opening a port for wcf service

$
0
0
It seems like one requirement that I've heard for production deployment of web services in the past is that a port must be opened to accommodate it.  Is this true?  Or is this only true in some scenarios?  It seems like an additional port should not need to be opened if the wcf service is hosted within a web app on iis....

how to use PROXY in CLIENT

$
0
0

proxy

Dim ObjProxy As New System.Net.WebClient
Dim prxy As New WebProxy(My.Settings.Proxy_Server, Integer.Parse(My.Settings.Proxy_Port))
prxy.Credentials = New NetworkCredential(My.Settings.Proxy_User, My.Settings.Proxy_Password, My.Settings.Proxy_Domain)
ObjProxy.Proxy = prxy

by using the above code, able to create proxy, but do not how to use the above proxy to the below client.

  Using client = New EndUserClient("defaultEP_EU")
                Using scope = New OperationContextScope(client.InnerChannel)
                    Dim header = MessageHeader.CreateHeader("Username", "hc", Username)
                    OperationContext.Current.OutgoingMessageHeaders.Add(header)
                    header = MessageHeader.CreateHeader("Password", "hc", Password)
                    OperationContext.Current.OutgoingMessageHeaders.Add(header)
                    If client.Ping() Then
                        ' Dim NewUserId As Object = client.GetUserByUsername(mob)
                        Dim subcheck As New EndUser
                        subcheck = client.GetUserByUsername(mob)
                    End If
                End Using
            End Using

datacontracts with list datamembers

$
0
0

Hello - I'm creating a DataContract for a WCF service. One of the DataMembers needs to be a list of objects. The service compiles but when I add a reference to the service in another project the list property is exposed as an array. Is this the expected behavior/constraint with WCF? If so then should I simply define DataMember lists as arrays since it appears to get converted to an array anyway?

Create xml in web service using Soap Header

$
0
0

Hi,

how do i create xml on my desire in web service using Soap Header

forExample i want that when i test the xml it should be create like this

<Employee>
<EmployeeDetails>
<Name>Taha</Name>
<Designation>Software Engineer</Designation>
<Company>Abc Limited<Company>
</EmployeeDetails>

<PersonalDetails>
<DOB>XX-XX-XXXX</DOB>
<BloodGroup>XX</BloodGroup>
<Status>Single</Status>
</PersonalDetails>
</Employee>

how should i create as above xml using SOAP Header attribute, i create something like the all the tags EmployeeDetails and all the tag under EmployeeDetails, but unable to add the EmployeeDetails tag under Employee tag here is my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "S:employeeDetail.Summry")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]

public class Service : System.Web.Services.WebService
{
    public class EmployeeDetail : SoapHeader
    {
        public string Name = "0.0";
        public string Designation = "1";
        public string Company = "Credit";
    }
        
    public Service () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }
    public EmployeeDetail employeeDetail;

    [WebMethod]
    [SoapHeader("employeeDetail", Direction = SoapHeaderDirection.InOut)]
    public void HelloWorld()
    {
        if (employeeDetail == null) { employeeDetail = new EmployeeDetail(); }
    }
}



 

Viewing all 555 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>