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

Protocol Error "Object moved"

$
0
0

My web service works fine when I test with Localhost, but when I deploy to the web I get a Protocol error with the message

Message=The request failed with the error message:
--
<head><title>Document Moved</title></head>
<body><h1>Object Moved</h1>This document may be found <a HREF="http://XXXX.org.uk/WSLog.asmx">here</a></body>
--.
Where the HREF is the correct address of the service.

I created the service interface with the "Add service reference/advanced/Add Web reference" in Visual studio 2013

I assume I'm missing a setting in the web config or the host site ("Anonymous authentication" is checked on the host)


Calling a WCF service self hosted as windows service from a Windows service

$
0
0

Hi,

My requirement is to call a WCF service hosted in individual machines as a Windows Service from a Windows Service which is also be placed in all the machines. The WCF service is having NetNamedPipe Binding and while trying to access the WCF service from the Windows Service it is working great by passing the username of the machine, but the same is not working when we install the Windows Service, it is asking for Username as well as Password.

To explain in a line Calling wcf is working fine before installing windows service, but the same is asking for password post installation of the windows service.

Requesting anyone to provide an optimal solution for the problem

WCF Data service query

$
0
0

Hello,

I am using WCF data service to get data from sql database. I have written one query which takes longer time to execute. i want to improve this expression to get only the columns i need. I could get column from Table1 but not able to find column from Table2 in example below. Appreciate if anyone could help me with this.

var list = DataContext.Table1.Expand("Table2").Where(T => T.Name = "Test").ToList();

on the similar lines i have one expression which goes like:

var list = DataContext.Table1.Expand("Table2/Table3").Where(T => T.Name = "Test").ToList();

how to get specific columns from 3 tables. alternatively please suggest how can i reduce the response time.

Is there a way to strip off the namespace of my object properties for XML serialization

$
0
0

I hope i am explaining this correctly.

I am getting the error below, and thinking it has something to do with the namespace (see highlighted)

Is there a way to strip off the namespace when I build up my object to serialize to XML.

So when i build up the object (see below)

I thing the issue is the namespace that is showing up before the "HCIM_IN_GetDemographics"

Here is my debugging code on when i serialize:

System.Diagnostics.Debug.WriteLine(Serialize(batchRequest));

public static string Serialize(Object obj)
        {
            try
            {

                using (var sw = new StringWriter())
                {
                    string objType = obj.GetType().Name.ToString();

                    var serializer = new XmlSerializer(obj.GetType(), new Type[] { obj.GetType() });
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add("hl7", "urn:hl7-org:v3");

                    serializer.Serialize(sw, obj, namespaces);
                    return sw.GetStringBuilder().ToString();
                }

            }
            catch (Exception e) { return e.Message; }
        }

I guess my question is, (assuming the Namespace is the issue)  Is there anyway to remove that namespace, so that when i serialize the object, it won't give me that error?

Any ideas are greatly appreciated.

Thanks in advance !

The operation could not be completed. The parameter is incorrect

$
0
0

I'm getting "The operation could not be completed. The parameter is incorrect" when I build the solution. I tried deleting the .suo file as suggested in another thread

but that didn't work.

Can anyone help? Thanks.

+++++++++++++++++++++++++++++ IService1.cs ++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{

[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/SayHello/{Name}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string SayHello(string Name);
}
}

+++++++++++++++++++++++++++++++++++ Service1.svc.cs ++++++++++++++++++++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public string SayHello(string name)
{
return string.Format("Hello, {0}", name);
}
}
}

+++++++++++++++++++++++++++++++ web.config +++++++++++++++++++++++++++++++++++++++++++++++++++

<?xml version="1.0"?>
<configuration>

<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6"/>
<httpRuntime targetFramework="4.6"/>
<!--<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>-->
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WcfService2.Service1" behaviorConfiguration="ServiceBehavior">

<endpoint binding="webHttpBinding" contract="WcfService2.IService1" behaviorConfiguration="web">


</endpoint>
</service>

</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<!--<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>-->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<!--<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
-->
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<!--
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>-->


</configuration>

How to ignore security certificate in web service in c# in visual studio

$
0
0

I have uploaded my web services to public IP.

However when I try access that URL it gives me privacy error that "Your connection is not private. Attackers might be .... "

NET::ERR_CERT_COMMON_NAME_INVALID

-------

How can we by-pass this privacy error? What code we need to add in web service to ignore this?

If I click advanced and then click "proceed to ip-address (unsafe)", it shows me web service methods. But if I try to invoke any of the methods , it gives me below error,

Site can't be reached

Took too long to respond.

ERR_CONNECTION_TIMED_OUT

How should I able to run the web service?

How to suppress header in SOAP response from C# web service

$
0
0

We're working with a client who uses Java to call our .NET web service.  We've received their request and responded successfully, but they're saying they can't process the response because of the SOAP headers. What they want us to do is to send an empty header instead.  How do I control that?

Current response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<ActivityId CorrelationId="ec996ca1-9999-9999-9999-50fce66eb706" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="_0">
<u:Created>2018-02-12T17:16:24.545Z</u:Created>
<u:Expires>2018-02-12T17:21:24.545Z</u:Expires>
</u:Timestamp>
</o:Security>
</s:Header>
<s:Body>
<MyResponse xmlns="http://xmlns.oracle.com/integration/b2b" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Status>Success</Status>
<ErrorMessage i:nil="true" xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"></ErrorMessage>
</MyResponse>
</s:Body>
</s:Envelope>

Intended response:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header></s:Header>
<s:Body>
<MyResponse xmlns="http://xmlns.oracle.com/integration/b2b" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Status>Success</Status>
<ErrorMessage i:nil="true" xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"></ErrorMessage>
</MyResponse>
</s:Body>
</s:Envelope>

Call Webservice from JS, sending some data

$
0
0

hi,

I have a webservice created with asp, which is:

Imports System
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols<System.Web.Script.Services.ScriptService()><WebService(Namespace:="http://tempuri.org/")><WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)><Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Public Class WBS_Actions
    Inherits System.Web.Services.WebService<WebMethod()>
    Public Sub TrackAction(byval sText as string)
        Dim path As String = "c:\MyTest.txt"
        Using fs As FileStream = File.Create(path)
            Dim info As Byte() = New UTF8Encoding(True).GetBytes(sText)
            ' Add some information to the file.
            fs.Write(info, 0, info.Length)
        End Using
    End Sub

End Class

On anoter website, I have a JS that calls this webservice like this:

function ActionDone() {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'http://localhost:57358/WBS_Actions.asmx/TrackAction', true);
    xhr.setRequestHeader('Content-type', 'text/plain');
    xhr.send("test");
}

Now, the issue is that the file is not created with that code. Instead, if I changed the webservice to the code below, the file is created, but I am missing the option to send data from JS to the webservice.

Public Sub TrackAction()
        Dim path As String = "c:\MyTest.txt"
        Using fs As FileStream = File.Create(path)
            Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is my text")
            ' Add some information to the file.
            fs.Write(info, 0, info.Length)
        End Using
End Sub

Any help would be much appreciated, thanks!

imendimu


how to assign api key in asp.net webform ?

$
0
0

Hi guys,

how to assign api key in asp.net webform ? 

i would like to call rest api value from this url "https://api.rajaongkir.com/starter/province?id=12"

to call api value i must assign API key from my codebehind, how to add api key in my codebehind ?

i just get tutorial in php version, how to in asp.net ? 

this is code api key if using PHP.

<?php$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.rajaongkir.com/starter/province?id=12",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array("key: your-api-key"
  ),
));$response = curl_exec($curl);$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

?>

Thank you & Regards.
Wibowo Wiwit

How to read Json Data Posted from One WCF Service to Another WCF Service

$
0
0

Hi Team,

There would Incoming Json Lets say below is the Json Data Would be posted to my Our WCF Service.

{

   "JobRequest":[

   {

   "Sourceid": 0,

   "Locationid": 0,

   "FeedDate": "2018-02-02T10:43:41.536Z",

   "RequestedBy": "string ",

   "PONumber": "string",

   "IncidentNumber": "string",

     "Priority":0,

   "JobTypeisPickup":0

   }

   ],

"Pickup":[

   {

   "EarliestDate": "2018-02-02T10:43:41.536Z",

   "LatestDate": "2018-02-02T10:43:41.536Z",

   "TimeofDay": "string"

   }

   ],

"Delivery":[

   {

   "DeliverySentDate": "2018-02-02T10:43:41.536Z",

   "EstimatedArrivalDate": "2018-02-02T10:43:41.536Z",

   "TrackingNumber": "string"

   }

   ],

   "EquipmentDetails":[

   {

   "EquipmentType": "string",

   "EstimatedQty": 0,

   }

   {

   "EquipmentNotes": "string",

   "EquipmentLocation":"string",

   "IsPacked": 0 ,

    "NumberOfPallets":0,

    "LocationtoPalletize":"string"

      }

   ],

   "PartDetails":[

   {

   "PartNo": "string",

   "QtyExpected": 0

   }

   ],

   "Attachments":[

   {

   "FileName": "string",

   "Filetype": "string",

   "Filebytes": "string"

   }

   ]

}.

So Now my question is how to read the the data from the WCF Service .  How should i Create Request Object Class in this case .

Problems with web.config

$
0
0

Hi all,

I'm new here, i'm a new programmer and i'm having some problems with my web service. Probably this problem is resolved in anther thread but i can't find it. So sorry if it's just a repetition.

That said, i'll explain my problem in the more accurate way i can:

I have a web service for REST and SOAP, it's working great in localhost and now i'm trying to put it on a machine. Here is my web.config file:

<?xml version="1.0"?><configuration><system.web><compilation targetFramework="4.0" debug="true" /><customErrors mode="Off" /></system.web><system.serviceModel><serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false"/><services><service behaviorConfiguration="WebServiceBehavior" name="WcfUTOasmx.UTO"><host><baseAddresses><add baseAddress="http://www.LocalU_TillOneYougo-tech.com/"/> </baseAddresses></host><endpoint address="" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="WcfUTOasmx.IUTO"/><endpoint address="soap" binding="basicHttpBinding" contract="WcfUTOasmx.IUTO"/></service></services><behaviors><endpointBehaviors><behavior name="jsonBehavior"><webHttp helpEnabled="true"/></behavior></endpointBehaviors><serviceBehaviors><behavior name="WebServiceBehavior"><serviceMetadata httpGetEnabled="true"/><serviceDebug includeExceptionDetailInFaults="false"/></behavior></serviceBehaviors></behaviors><bindings><webHttpBinding><binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"/></webHttpBinding></bindings></system.serviceModel><system.web><webServices><conformanceWarnings><remove name="BasicProfile1_1"/></conformanceWarnings></webServices><!--<compilation debug="true" targetFramework="4.0"/>--><httpRuntime targetFramework="4.5"/></system.web><system.webServer><modules runAllManagedModulesForAllRequests="true"/></system.webServer></configuration>

In my UTO.svc.cs file I have this two rows

[WebService(Namespace = "http://www.LocalU_TillOneYougo-tech.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

And here there is my .asmx file:

<%@ WebService Language="C#" Class="WcfUTOasmx.UTO" %>

I can't understand why, when i digit http://www.localu_tilloneyougo-tech.com:49351/UTO.svc/resetHW the response is "impossible to find the IP address"

Thanks for your help.

Luca

Console App calls WCF service

$
0
0

I am trying to see what my ConsoleApplication code should look like to issue the post. I made an attempt. Can anyone help?

++++++++++++++++++ IRESTServiceImpl.cs +++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace RESTService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IRestServiceImpl" in both code and config file together.
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "auth")]
ResponseData Auth(RequestData rData);

}
[DataContract(Namespace = "http://www.eysnap.com/mPlayer")]
public class RequestData
{
[DataMember]
public string details { get; set; }
}
public class ResponseData
{
[DataMember]
public string Name { get; set; }

[DataMember]
public string Age { get; set; }

[DataMember]
public string Exp { get; set; }

[DataMember]
public string Technology { get; set; }
}
}

+++++++++++++++++++++++++++++++++++++ RESTServiceImpl.svc.cs +++++++++++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace RESTService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RestServiceImpl" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select RestServiceImpl.svc or RestServiceImpl.svc.cs at the Solution Explorer and start debugging.
public class RestServiceImpl : IRestServiceImpl
{
public ResponseData Auth(RequestData rData)
{
//Call BLL here
var data = rData.details.Split('|');
var response = new ResponseData
{
Name = data[0],
Age = data[1],
Exp = data[2],
Technology = data[3]
};
return response;
}
}
}

+++++++++++++++++++++++++++++++++++++++++++++++++ web.config ++++++++++++++++++++++++++++++++

<?xml version="1.0" encoding="utf-8"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<services>
<service name= "RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding ="webHttpBinding" contract="RestService.RestServiceImpl" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />

</dependentAssembly>

</assemblyBinding>

</runtime>
</configuration>

++++++++++++++++++++++++++++++++++++ Console Application +++++++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string data = "auth";
string url = "http://localhost/RESTService/RestServiceImpl.svc/" + data;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "text/xml; charset=utf-8";
req.ContentLength = 0;
System.Net.WebResponse resp = req.GetResponse();
using (Stream stream = resp.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
Console.WriteLine(reader.ReadToEnd());
}
}
Console.ReadLine();
}
}
}

How to connect web service with android

$
0
0

Hello, 

I have written my web service methods code , and I don't know what to do next .

How I can let my android app accessing it ?

My project is local ( my PC is the server and the app will be installed on my phone)

The underlying connection was closed: An unexpected error occurred on a receive.

$
0
0

Hi there.

when I run my web service I get these errors:

An error occurred while receiving the HTTP response to http://localhost:39268/AratimeService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.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 IAratimeService.GetAllCities()
   at AratimeServiceClient.GetAllCities()

Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)

Inner Exception:
An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

here are my codes:

[OperationContract]
IQueryable<City> GetAllCities();
...
...
public IQueryable<City> GetAllCities()
        {
            IQueryable<City> AllCities = db.Set<City>();
            return AllCities;
        }
...
...

String or binary data would be truncated. The statement has been terminated

$
0
0

Hello,

After hosting service in IIS ; it shows me an error when trying to add a new record to a table .

Note: I read about this error and all the explanations were about the size.  I'm sure  with what I'm entering, that's not the problem.

what it shows exactly  is :

System.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at server.WebService.AddUser(String name, String phone, String email, String password) in C:\Users\user\Desktop\server\server\WebService.asmx.cs:line 139 ClientConnectionId:a365a08e-f7e3-491c-a378-1fa1f505d723 Error Number:8152,State:4,Class:16


Calling WCF Service

$
0
0

How would I call this web service from a Console App? Could you show me the code? Thanks.

++++++++++++++++++ IRESTServiceImpl.cs +++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace RESTService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IRestServiceImpl" in both code and config file together.
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "auth")]
ResponseData Auth(RequestData rData);

}
[DataContract(Namespace = "http://www.eysnap.com/mPlayer")]
public class RequestData
{
[DataMember]
public string details { get; set; }
}
public class ResponseData
{
[DataMember]
public string Name { get; set; }

[DataMember]
public string Age { get; set; }

[DataMember]
public string Exp { get; set; }

[DataMember]
public string Technology { get; set; }
}
}

+++++++++++++++++++++++++++++++++++++ RESTServiceImpl.svc.cs +++++++++++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace RESTService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RestServiceImpl" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select RestServiceImpl.svc or RestServiceImpl.svc.cs at the Solution Explorer and start debugging.
public class RestServiceImpl : IRestServiceImpl
{
public ResponseData Auth(RequestData rData)
{
//Call BLL here
var data = rData.details.Split('|');
var response = new ResponseData
{
Name = data[0],
Age = data[1],
Exp = data[2],
Technology = data[3]
};
return response;
}
}
}

+++++++++++++++++++++++++++++++++++++++++++++++++ web.config ++++++++++++++++++++++++++++++++

<?xml version="1.0" encoding="utf-8"?>
<configuration>

<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.serviceModel>
<services>
<service name= "RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding ="webHttpBinding" contract="RestService.RestServiceImpl" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true" />
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />

<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />

</dependentAssembly>

</assemblyBinding>

</runtime>
</configuration>

The content type text/html of the response message does not match the content type of the binding

$
0
0

Hi All,

I am getting following errors while push data using a wcf service. Not getting proper solution to fix this problem. Can anyone help me here.

Message:The content type text/html of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:

HOW TO WRITE OR UPLOAD FILE USING WCF SERVICE TO ANOTHER SERVER

$
0
0

HI TEAM,

I  have a Client WEB SERVICE which gives send Few files to my MY WCF SERVICE.   They are sending  the data in  the file byte array , and these   files we need to  created on the remote server location lets say ...       //121.122.122.133//ContentFolder// .  So my question is when i was using WEB Forms in that FileUpload.Saveas Works properly. BUT from WCF service how can i create  write these files in that folder.  Please provide Suggestions

SOAP - problem with deserialization of array of custom objects

$
0
0

Hi.

I`ve got some problems when deserilizing array of objects in one of the web services. The following class was generated by the dotnet-svcutil and during deserialization countField is deserilized properly while the clientsField which is of type clientDetails[] is always null.

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "0.5.0.0")]
//[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.Xml.Serialization.SoapTypeAttribute(Namespace="http://www.example.org/ResellerAPI/")]
public partial class clientDetailsArray
{
    private int countField;
    private clientDetails[] clientsField;
    /// <remarks/>
    public int count
    {
        get
        {
            return this.countField;
        }
        set
        {
            this.countField = value;
        }
    }
    /// <remarks/>
    public clientDetails[] clients
    {
        get
        {
            return this.clientsField;
        }
        set
        {
            this.clientsField = value;
        }
    }
}

As far as I debugged it the source XML structure received from web service is correct and the problem must be with the code responsible for deserilization. When I enable XML debugging and step into the whole process I can find the following piece of code that is theoretically responsible for deserilization of the clientsField and it returns null no matther what:

        object Read610_Array() {
            // dummy array method
            UnknownNode(null);
            return null;
        }

Why is this method generated in such way and how to fix it?

Web Config syntax errors

$
0
0

I am getting the following errors in syntax... can you help? Using VS 2015 and NET Framework 4.5

++++++++++++++++++ web.config file ++++++++++++++++++++++++++++

<?xml version="1.0"?>
<configuration>

<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<services>
<service name="WcfRestBased.Service1"

++++++++++++ error here... The 'behaviorConfiguration' attribute is invalid. The value 'myService1Behavior' is invalid according to its datatype
'serviceBehaviorConfigurationType' - the Enumeration constraint failed. +++++++++++++++++++++

behaviorConfiguration="myService1Behavior">

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

<endpoint name="webHttpBinding"

address=""

binding="webHttpBinding"

contract="WcfRestBased.IService1"

++++++++++++ and error here... The 'behaviorConfiguration' attribute is invalid. The value 'webHttp' is invalid according to its datatype
'endpointBehaviorConfigurationType' - the Enumeration constraint failed. +++++++++++++++++++++

behaviorConfiguration="webHttp"

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

>
</endpoint>
<endpoint name="mexHttpBinding"

address="mex"

binding="mexHttpBinding"

contract="IMetadataExchange"

/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking"/>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
preCondition="managedHandler"/>
</modules>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>

</configuration>

++++++++++++++++++++++++++++++++++++ IService1.cs +++++++++++++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfRestBased
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{

[OperationContract(Name = "PostSampleMethod")]
[WebInvoke(Method = "POST",
UriTemplate = "PostSampleMethod/New")]
string PostSampleMethod(Stream data);

[OperationContract(Name = "GetSampleMethod")]
[WebGet(UriTemplate = "GetSampleMethod/inputStr/{name}")]
string GetSampleMethod(string name);
// TODO: Add your service operations here
}


// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";

[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}

[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}

+++++++++++++++++++++++++++++++ Service1.svc.cs ++++++++++++++++++++++++++++++++

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfRestBased
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
{
public string PostSampleMethod(Stream data)
{
// convert Stream Data to StreamReader
StreamReader reader = new StreamReader(data);
// Read StreamReader data as string
string xmlString = reader.ReadToEnd();
string returnValue = xmlString;
// return the XMLString data
return returnValue;
}
public string GetSampleMethod(string strUserName)
{
StringBuilder strReturnValue = new StringBuilder();
// return username prefixed as shown below
strReturnValue.Append(string.Format
("You have entered userName as {0}", strUserName));
return strReturnValue.ToString();
}
}

Viewing all 555 articles
Browse latest View live


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