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

SQL, Select in Looping returning repeated value

$
0
0

I have been working on a project for a very long time and I can't seem to find out how to do it. I have a looping code and a function combined but can't seem to get the output I wanted to see.

My code is like this:

WITH CTE AS
(
SELECT 1 as Day
UNION ALL
SELECT Day+1 FROM CTE
WHERE Day < 15
), Name as (Select * from fn_logs(@Month, @Year,@date_from,@date_to)

)

SELECT CTE.Day,
CASE WHEN Name.DAtee != CTE.Day THEN Name.Fullname ELSE Name.Fullname END as Fullname,
CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.AMIN END as AMIN,
CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.AMOUT END as AMOUT,
CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.PMIN END as PMIN,
CASE WHEN Name.DAtee != CTE.Day THEN ' ' ELSE Name.PMOUT END as PMOUT
FROM CTE, Name

group by CTE.Day,Name.Fullname,Name.AMIN,Name.AMOUT,Name.PMIN,Name.PMOUT

where the **Name.DAtee** gets the day of the date
The output I wanted to happen was like:

Day Fullname   AM-IN   AM-OUT   PM-IN   PM-OUT
1   Ara Ast    8:00    12:00    12:03    5:00
2   Ara Ast    7:51    12:22    12:23    5:10
3   Ara Ast
1   Clara Est  8:01    12:12    12:25    5:07
2   Clara Est
3   Clara Est  7:41    12:02    12:15    5:00


I wanted to show all the days a single employees has logged and when no date was logged, it will automatically show no value. The output I get was like:

Day Fullname  AM-IN  AM-OUT  PM-IN  PM-OUT
1   Ara Ast   8:00   12:00   12:03  5:00
2   Ara Ast
3   Ara Ast
1   Ara Ast
2   Ara Ast   7:51   12:22   12:23   5:10
3   Ara Ast
1   Ara Ast
2   Ara Ast
3   Ara Ast

The values seem to repeat and whenever the value was not equal to the date, it prints the no value. Sorry I am kinda still in the learning stage of the sql server coding.

Thanks in advance.


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

How to tcp/ip header

$
0
0

Dear all, the below code is how am returning a tcp message to a client machine, but the company demanded i should be adding a tcp/ip header to the message. They said the header should be a 2-byte header prefixed which will indicate the length on the TCP/IP stream. can anybody help me on how i can include the header on the below code

	private static void Send(Socket handler, String data)
	{
		// Convert the string data to byte data using ASCII encoding. 
		byte[] byteData = Encoding.ASCII.GetBytes(data);
		// Begin sending the data to the remote device. 
		handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
	}

Validate input parameters to WCF web service

$
0
0

I have WCF web service that takes 2 dates as input parameters. 

I need to validate that the difference between two dates is not larger than 2, and return error code for the user for this.

 [OperationContract]
 List<PERSONAL> getPersonalChangeList(DateTime fromDate, DateTime toDate);

please any helfp?

How to get web application url in webservice

$
0
0

I have application with two components, mobile application (e.g. iPad, android tab) as front-end and web application as back-end.

Whatever data transfer happens at mobile application is through different web services written in ,asmx page in my web application. 

Now in one of my web services I send email notification to client. In that email I need to provide my backend login page URL link to user. So user can access back end application using his/her laptop using that link. If user clicks that link, it should take him to web application login page.

How can I get that URL link in web service?

So suppose this is my web application login page URL, 

http://IP address of web server/TestApplication/Login.aspx.

So how can I get this link in web service?

problem with web service asmx

$
0
0

Hi,

i have a web service asmx works correctly in visual studio  but when i deply it in IIS7  return always null value 

 [WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void Getinfoweb(........)

{

System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
Suivi rows = new Suivi();
rows = Service.GetInfo(........);
this.Context.Response.ContentType = "application/json; charset=utf-8";
this.Context.Response.Write(serializer.Serialize(rows));

List Methods in WCF Service

Why don't WCF support "testing" page like web service (.asmx)?

$
0
0

When you create a web service with ASP.NET it automatically creates a test page. I wonder if WCF supports a test page as web service (.asmx) or not. If the answer is no and why WCF do not create a test page as web service. Please help me explain it. Thanks


HTTP Error 500.21 - Internal Server Error .NET WCF service

$
0
0
<div class="votecell post-layout--left"></div> <div class="postcell post-layout--right"> <div class="post-text" itemprop="text">

I uploaded a wcf service to a web hosting and it was working fine, I could access to it, but suddenly it started throwing this error when I try to open it

IIS 8.5 Detailed Error

HTTP Error 500.21 - Internal Server Error Handler "svc-Integrated" has a bad module "ManagedPipelineHandler" in its module list

I've been searching and for what I understand it has something to do with the requisites for ASP.NET, it was suggested to run this command:

aspnet_regiis.exe -i

But since I'm using a shared hosting it's not much of an option, I don't know if I can add a handler to my web config or if I have to contact my provider to solve it.

The strange thing for me is that I was working with it without problems for months and it just suddenly threw that error.

Here's my webconfig:

<?xml version="1.0" encoding="utf-8"?><configuration><configSections><sectionname="entityFramework"type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"requirePermission="false"/><!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections><appSettings><addkey="aspnet:UseTaskFriendlySynchronizationContext"value="true"/></appSettings><system.web><trustlevel="Full"></trust><customErrorsmode="Off"></customErrors><compilationtargetFramework="4.5.2"debug="true"><assemblies><addassembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/><addassembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/><addassembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/><addassembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/><addassembly="MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/></assemblies><buildProviders><addextension=".edmx"type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"/></buildProviders></compilation><httpRuntimetargetFramework="4.5.2"/><globalizationculture="es"uiCulture="es-mx"/></system.web><system.serviceModel><behaviors><serviceBehaviors><behavior><!-- To avoid disclosing metadata information, set the values below to false before deployment --><serviceMetadatahttpGetEnabled="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 --><serviceDebugincludeExceptionDetailInFaults="true"/></behavior></serviceBehaviors></behaviors><protocolMapping><addbinding="basicHttpsBinding"scheme="https"/></protocolMapping>><serviceHostingEnvironmentaspNetCompatibilityEnabled="true"multipleSiteBindingsEnabled="true"/><bindings><basicHttpBinding><bindingmaxBufferPoolSize="2147483647"maxBufferSize="2147483647"maxReceivedMessageSize="2147483647"><readerQuotasmaxDepth="2147483647"maxStringContentLength="2147483647"maxArrayLength="2147483647"maxBytesPerRead="2147483647"maxNameTableCharCount="2147483647"/><securitymode="None"/></binding></basicHttpBinding></bindings></system.serviceModel><system.webServer><httpErrorserrorMode="Detailed"/><aspscriptErrorSentToBrowser="true"/><modulesrunAllManagedModulesForAllRequests="true"/><!--
        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.
      --><directoryBrowseenabled="true"/><handlers><removename="ExtensionlessUrlHandler-Integrated-4.0"/><removename="OPTIONSVerbHandler"/><removename="TRACEVerbHandler"/><addname="ExtensionlessUrlHandler-Integrated-4.0"path="*."verb="*"type="System.Web.Handlers.TransferRequestHandler"preCondition="integratedMode,runtimeVersionv4.0"/><addname="svc-Integrated"path="*.svc"verb="*"type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"preCondition="integratedMode"/></handlers></system.webServer><connectionStrings><addname="mydatabaseEntities"connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=www.myserver.com;user id=myuser;password=mypassword;database=mydatabase&quot;"providerName="System.Data.EntityClient"/></connectionStrings><system.data><DbProviderFactories><removeinvariant="MySql.Data.MySqlClient"/><addname="MySQL"description="ADO.Net driver for MySQL"invariant="MySql.Data.MySqlClient"type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/></DbProviderFactories></system.data><entityFramework><defaultConnectionFactorytype="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"><parameters><parametervalue="v13.0"/></parameters></defaultConnectionFactory><providers><providerinvariantName="System.Data.SqlClient"type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/><providerinvariantName="MySql.Data.MySqlClient"type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/></providers></entityFramework><runtime><assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentityname="MySql.Data"publicKeyToken="c5687fc88969c44d"culture="neutral"/><bindingRedirectoldVersion="0.0.0.0-6.9.9.0"newVersion="6.9.9.0"/></dependentAssembly></assemblyBinding></runtime></configuration><!--ProjectGuid: 358c49ac-3d89-4b28-8a2e-15304c1a48e2-->

If someone has a suggestion I'd appreciate it

</div> </div>

Share two endpoint

$
0
0

Hi All,

How to share/expose two methods to two different users in wcf.

Service Interface:

interface IArithmeticOperation
{
  [OperationContract]
  decimal AddTwoNemeric(decimal first, decimal second);
  [OperationContract]
  decimal SubtractTwoNemeric(decimal first, decimal second);
}

Service:

class ArithmeticOperation: IArithmeticOperation
{
  public decimal AddTwoNemeric(decimal first, decimal second)
  {
      return (first + second);
  }

  public decimal SubtractTwoNemeric(decimal first, decimal second)
  {
      return (first - second);
  }
}

endpoint: http://localhost:59338/ArithmeticOperation.svc

Above service expose two actions like arithmetic Addition and Subtraction, but my requirement is how I share the endpoint two different clients with access restriction. 

Client A: Only able to access AddTwoNemeric service method

Client B: only able to access SubtractTwoNemeric service method 

Thanks,

SvcUtil error generating proxy from asmx assembly

$
0
0

Hi  I am trying to use SvcUtil  with asmx webservice to generate proxy class I get error: cannot generate XmlSerilaizer types for assembly .....No service contract types were found.

I tried to add service contract but it does not exist for asmx.

my command :  SvcUtil.exe    directory/bin/WebService1.dll   /out: directory/myproxy.cs

I noticed the command works fine when supplying end point  of web service in IIS: SvcUtil.exehttp://localhost....    

proxy creation required for Rest based WCF service

$
0
0

we know that when client consume wcf service then they have to add reference first to create proxy but for web api no proxy is required. so tell me if we create Rest based WCF service then also client has to add service reference to create proxy before service call?

guide me please. thanks

I have one link of wcf data services 4.5 is it latest wcf and if not i need some links of msdn to read from.

Access web service on localhost from Android device

$
0
0

I'm attempting to make ajax calls from a android device to a web service that's hosted locally (i.e. localhost). However, receiving the following error:
Refused to connect to 'http://localhost:52437/MyServiceContract.svc/Read_Customer/11sj82' because it violates the following Content Security Policy directive: "connect-src
'self' http://localhost:52437/MyServiceContract.svc".

I've included the web service in a CSP directive via meta tag in the app but to no avail. Here's sample html tag:

<meta http-equiv="Content-Security-Policy" content="connect-src 'self' http://localhost:52437/MyContract.svc; script-src 'self' https://maps.googleapis.com; default-src 'self' https://ssl.gstatic.com data: gap: 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

I've tried to use ADB reverse socket whereby the port no. for localhost is added. Here's a sample of the adb command:

adb.exe reverse tcp:4000 tcp:4000

After doing so, I'm able to access and retrieve data from the web service via web browser on the  device.

In lieu of including the directives in the meta tag, I also tried using the config.xml but to no avail.

Lastly, I've been able to successfully access the web service from the simulator.


Any help is appreciated.

Authentication SPN?

$
0
0

Hello Community
I need help, I have a web service (http: //web/service1/home.asmx) that needs to make a call to another web service (http: //web/service2/personas.asmx/listAll) but the latter needs integrated authentication .
How can I configure a web service (http: //web/service1/home.asmx) to transmit its authentication


Can i use a proxyAddress when using net.tcp binding ?

$
0
0
Hi
I am using net.tcp binding in my wcf service. But can i use a proxy in the config ? I am trying to use wcftestclient but where can i set the proxy Address ?

Thanks

Error making a POST request with Bearer Token to REST API using C#

$
0
0

I am able to POST to an REST API with Basic authentication and getting  successful response back, along with the Token. Now I need to pass the token to the site. I am having some difficulties as to passing the Bearer Token. I get a Forbidden error. Can some please give some thoughts where am I missing something?

Thanks.

 String username = "username";
        String password = "pwd";
        string URL = "url/login";
        string URL2 = "url/sessions"
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
        request.Method = "POST";
        request.ContentType = "application/json";
        request.ContentLength = 0;

        request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + password)));
        using (var response = request.GetResponse())

        using (var reader = new StreamReader(response.GetResponseStream()))
        {

            string result = reader.ReadToEnd();
            txtResponse.Text = Convert.ToString(result);
        }

      using (var reader = new StreamReader(response.GetResponseStream()))
        {

            string result = reader.ReadToEnd();
            txtResponse.Text = Convert.ToString(result);
            JObject joResponse = JObject.Parse(result);
           apitoken = (string)joResponse["token"];

         }
//I get the correct token from above, but I get Forbidden error
        WebRequest request1 = HttpWebRequest.Create(URL2);
        request1.Headers.Add("Authorization", "Bearer " + apitoken);
        request1.Method = "POST";
        request1.ContentType = "application/json";
        var resp = request1.GetResponse();

Why ObjectResult is used as return type of webget method in wcf dataservices

$
0
0
<div class="votecell post-layout--left"> <div class="vote">0 down vote favorite<div class="favoritecount"></div> </div> </div> <div class="postcell post-layout--right"> <div class="post-text" itemprop="text">

i am reading wcf from here "https://docs.microsoft.com/en-us/dotnet/framework/data/wcf/how-to-define-a-service-operation-wcf-data-services"

and it says The method must return one of the following:

void(NothinginVisualBasic)IEnumerable<T>IQueryable<T>An entity type in the data model that the data service exposes.

A primitive class such as integer orstring.

but i can see webget is returning

[WebGet]publicSystem.Data.Objects.ObjectResult<dcHCGetCust>   getCusts(Nullable<long>CustId){returnthis.CurrentDataSource.uspGetCust(intProjectId);}

so please tel me what is it (objectResult) and where i can read it in wcf ( any link would be appreciatable)

yours sincerely

</div> </div>

WCF Service cannot find any service metadata. This may cause the client application to run improperly. Please check if the metadata is enabled.

$
0
0

Hi,

I am trying to debug an existing set of WCF services hosted under IIS. However on attempting to debug, the services fail to start with message,
"WCF Service cannot find any service metadata. This may cause the client application to run improperly. Please check if the metadata is enabled."

I have verified the web.config within the host project and binding, endpoints, contract names look good. Contract name matches the name in the code. This is a TFS controlled project and debugs fine on other user's machine. My hunch is that there might be machine settings some where that might be the cause of this. 

This is my interface definition:

namespace Services.Code.Contracts.Service
{
    [ServiceContract(Namespace = "http://Services.BPIntegration")]
    [SuppressMessage("ReSharper", "InconsistentNaming")]
    public interface IPolarisBPService
    {
        [OperationContract]
        [FaultContract(typeof(IncorectDataFault))]
        [FaultContract(typeof(RecordNotFoundFault))]
        CreateBusinessPartnerResponse CreateBusinessPartnerOut(Guid clientBrokerId, BusinessPartnerInfo data);

        [OperationContract]
        [FaultContract(typeof(IncorectDataFault))]
        [FaultContract(typeof(RecordNotFoundFault))]
        IEnumerable<Tuple<string, EventLogEntryType>> UpdateBusinessPartnerIn();

        [OperationContract]
        Dictionary<string, string> GetIntegrationMappings(Dictionary<string, string> sourceSchemaSourceValuePairs);

    }
}

This is the excerpt web.config from the host project:

<service name="Services.Code.Behavior.PolarisBPService" behaviorConfiguration="PolarisBPServiceBehavior"><endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="Services.Code.Contracts.Service.IPolarisBPService"/></service>

Any help would be deeply appreciated.

Thanks!

Using cache in a web service

$
0
0

I have inherited a asmx web service that makes numerous database calls but doesn't cache any of the results.  Thus, each call to the web service hits the database.  I'd like to implement the use of caching to reduce the number of such calls and hopefully, improve overall performance.  Unfortunately, I've never used (or written) any type of caching logic.  Thus, I have several questions as follows:

1) How do I go about implementing cache logic in the web service?  I presume I should write a separate class but that is just a presumption as I've seen some examples which had cache logic written directly in a web method.  So, I'm looking for what would be the best practice for implementing cache logic into a web service.

2) One of the database queries checks for the existence of an  item and returns true if the item exists in the database. Otherwise, false is returned.  Would it be better to store the results of such a query in a dictionary (i.e. dictionary<string, boolean>) then cache the dictionary or could I simply use the item as the cache key and have the value be the boolean?  I like the idea of the latter because it seems easier but there could possibly be several thousand items resulting in several thousand cache keys.  Is that acceptable or would having so many cache keys cause issues?  I'm thinking not but haven't been able to find a definitive answer or whether this would go against best practices. 

3) Related to 2, if I need to use a dictionary, how could I add new items to the dictionary safely (i.e. how do I update cache in a thread safe manner)?  I've seen lots of postings showing how to read from cache or add a new value to it but not how to safely update an existing value.  

While I am sure I'll have more questions as I go along, hopefully, answers to the above will get me started down the right path.  Also, any examples, links, etc. are appreciated.

Thank you.

Viewing all 555 articles
Browse latest View live


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