|
pmcm wrote: the column with the button is empty If the column is empty that means you have code somewhere that is hiding the button, .Visible = false; or some other code that is messing something up.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
turns out there was a database query that runs to validate the server is in an admin group after the button is set, atm the query is returning null so this is why the button is being disabled. Thanks for all the advice/help
|
|
|
|
|
Glad to see that you narrowed it down.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hi all,
I have an Application that's using WPF, in which I have a ListBox as below, can I have similar kind of ListBox in HTML5 or can we have at least any other similar Control so that I can give same look and feel to the Customers that are using the Application. Any help is going to be very helpful, a code snippet a link or even a suggestion would be greatly helpful.
In the below xaml if you can replace < with < and > with > symbols it works. Is there any online tool to convert from xaml to HTML5 instead of downloading the application, because my company has download restrictions in the environment.
Here is the ListBox look like xaml:
<ListBox
Name="Members"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="166,80,0,0"
HorizontalContentAlignment="Left"
VerticalContentAlignment="Top"
ItemsSource="{Binding ElementName=SubscriberResults, Path=SelectedItem.Members}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel
VerticalAlignment="Top">
<TextBlock
VerticalAlignment="Top"
HorizontalAlignment="Left"
Text="{Binding Path=Name}"
Style="{StaticResource DataLabel}"/>
<TextBox
VerticalAlignment="Top"
HorizontalAlignment="Left"
Text="{Binding Path=SSN}"
FontSize="12"
BorderBrush="Transparent"
/>
<TextBlock
VerticalAlignment="Top"<br />
HorizontalAlignment="Left"
Text="{Binding Path=DOB, StringFormat=d}"
Style="{StaticResource DataLabel}"/>
<ListBox
ItemsSource="{Binding Path=MemberDetails}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBox
Text="{Binding Path=TranslatedDetail}">
<TextBox.Style>
<Style
TargetType="TextBox"
BasedOn="{StaticResource DataBox}">
<Style.Triggers>
<DataTrigger
Binding="{Binding Path=HasParsedData}"
Value="True">
<Setter
Property="FontWeight"
Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Click="Enroll_Click">
Enroll
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified 20-Dec-16 17:37pm.
|
|
|
|
|
WPF and HTML5 both are different technology, you can not directly convert XAML to HTML5, instead you need to search for a control that will work like a wpf list box, and for UI look you can create a CSS in HTML5
I think HTML5 <datalist> Element, will help you more. Here is listbox link
Html5 ListBox - JSFiddle[^]
Find More .Net development tips at : .NET Tips
The only reason people get lost in thought is because it's unfamiliar territory.
|
|
|
|
|
Hello,
I know that ASMX technology is considered legacy stuff. There's no need to lecture me on that point.
I am jumping in on an existing project that uses web services. (Editorial statement: Yuck!) When I test the webservice, I call up a similar URL to this:
https://OurServerVisibleToThePublic.com/FolderWithASMXFile/TheASMXFile.asmx
When I do this I get a page that contains all of the webservices we have defined. When testing, I click on one of them, a new page opens with parameters, I give it credentials and the XML that I am expecting is returned.
Now, I am attempting to call one or more web services from an ASP.NET application. The code looks like:
DIM WS as new CompanyWebServices.WebServicesClassName
GetData.DataSource = WS.MyWebServiceName(param1, param2, param3)
Unfortunately, the second line bombs, producing this fun error to solve:
Error: Server did not recognize the value of HTTP Header SOAPAction
At the top of the WSDL file, I have an attribute with a TargetNameSpace. The current setting is similar to this:
targetNamespace="https://OurServerVisibleToThePublic.com/FolderWithASMXFile"
When the app encounters the second line (i.e., WS.MyWebServiceName) I generate this error:
Message=System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: https://OurServerVisibleToThePublic.com/FolderWithASMXFile/MyWebServiceName.
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
* * * *
Does anyone know what I should specify in my TargetNameSpace? Does anyone actually like to troubleshoot web services? Thanks.
-- modified 20-Dec-16 16:11pm.
|
|
|
|
|
Take a look at the thread below called ASMX
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
Thanks for the response. However, I don't see the answer to my question in the two other threads about ASMX.
|
|
|
|
|
I guess you missed it.
Making a call to your asmx is no different than say making a call to a PayPal or FedEx WSDL Service.
One way to do it is by creating a service reference off the asmx file. After you do that, then you will get a set of SOAP Class calls to call the asmx functions in the asmx file. Now you need to package a SOAP call, and send it by using a HTTP bind with a service endpoint. The service reference you created will create the SOAP headers automatically and make the request, and return the response, in which you unpackage and process.
In essence, your creating a WSDL service from scratch, and writing or creating the structure needed just like a PayPal or FedEx SOAP service for your own internal use.
The post below contains all of the parts needed to do this in vb, you'll just have to pick it apart and create a simple sample to get started, and from there you can get more elaborate with it.
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
Hi jkirkerx, thanks for taking the time to contribute to our understanding of SOAP technology. However, I am trying to resolve an error. I perceive the source of the error to be the namespace that I am using in my WSDL file. I am trying to figure out how to move beyond the error by modifying the WSDL so that I know longer receive "Server did not recognize the value of HTTP Header SOAPAction."
You write: "One way to do it is by creating a service reference off the asmx file." That is not specific. This is what I said:
<me>
When I test the webservice, I call up a similar URL to this:
https://OurServerVisibleToThePublic.com/FolderWithASMXFile/TheASMXFile.asmx
...
Now, I am attempting to call one or more web services from an ASP.NET application. The code looks like:
DIM WS as new CompanyWebServices.WebServicesClassName
GetData.DataSource = WS.MyWebServiceName(param1, param2, param3)
...
At the top of the WSDL file, I have an attribute with a TargetNameSpace. The current setting is similar to this:
targetNamespace="https://OurServerVisibleToThePublic.com/FolderWithASMXFile"
</me>
I am trying to get help in specifying the targetNamespace. Thanks for your help so far, but I still don't have the answer to what I need.
Thanks,

-- modified 22-Dec-16 8:47am.
|
|
|
|
|
I am trying to populate the fields on a form from the database and the values aren't populating on the form. I have the value for the where clause hard coded in the code and it doesn't show the values that are in the database for that record on the form:
protected void Page_Load(object sender, EventArgs e)
{
this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
{
labelRID.Text = Request.QueryString["id"];
string rid = labelRID.Text;
string activityid = labelactivityid.Text;
if (!IsPostBack)
{
Bindactivitycodedropdown();
if (rid != "")
{
OracleConnection conn = new OracleConnection();
OracleCommand cmd = new OracleCommand();
conn.ConnectionString = strConnection;
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "Select RID, BUYING_ACTIVITY_ID, CUSTOMER_SOURCE_CODE, CUSTOMER_NAME, CUSTOMER_CITY, CUSTOMER_STATE, CUSTOMER_POSTAL_CODE, BUYING_ACTIVITY_CODE from BUYING_ACTIVITY WHERE RID = '55555'";
cmd.Parameters.Add(new OracleParameter("RID", Request.QueryString["ID"]));
OracleDataAdapter da = new OracleDataAdapter(cmd);
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
labelRID.Text = dr["rid"].ToString();
custname.Text = dr["customer_name"].ToString();
custcity.Text = dr["customer_city"].ToString();
custstate.Text = dr["customer_state"].ToString();
custpostalcode.Text = dr["customer_postal_code"].ToString();
activitycode.SelectedItem.Text = dr["buying_activity_code"].ToString();
custsrccode.Text = dr["customer_source_code"].ToString();
cvactivitycode.Enabled = false;
dr.Close();
conn.Close();
}
else
{
labelRID.Text = "";
custname.Text = "";
custcity.Text = "";
custstate.Text = "";
custpostalcode.Text = "";
activitycode.SelectedItem.Text = "";
custsrccode.Text = "C812 - NASA";
}
}
}
}
}
|
|
|
|
|
Bootzilla33 wrote:
activitycode.SelectedItem.Text = dr["buying_activity_code"].ToString();
...
activitycode.SelectedItem.Text = "";
You're still changing the text of the first item in the list, rather than selecting the correct item.
As I keep telling you, you need to set the SelectedValue property on the list, not the Text property on the SelectedItem .
activitycode.SelectedValue = dr["buying_activity_code"].ToString();
...
activitycode.SelectedValue = "";
If the other values are not populating, then there is no matching record in the database. If you think there is, then you're not looking at the same database as your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
I am trying to pass data from controller to view and tried all the three options ViewData, Viewbag and tempdata but none of them are working. When I am debugging, I can see the value but it is not displaying
Here is my code snippet:
[HttpPost]
public ActionResult AllProducts(int zip)
{
ViewBag.Message = "Welcome";
ViewData["Test"] = "Welcom to Test";
TempData["Testing"] = "Welcome to Testing";
return View("AllProducts");
}
This is a @ViewBag.Message
This is a @ViewData["Test"]
This is a @TempData["Testing"]
Output:
This is a
This is a
This is a
Can someone please tell me what am I doing wrong. Thanks in advance.
|
|
|
|
|
Are you sure you're accessing the correct action? The action you've shown will only respond to a POST request, so if you're just navigating to the URL in the browser, you'll be running a different action.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You are right, I have two action AllProducts() and [HttpPost]AllProducts(int zip)
What I am trying to do here is I am passing the zip parameter from json
[HttpPost]
public ActionResult AllProducts(int zip)
{
TempData["zipcode"] = zip;
TempData.Keep("zipcode");
return RedirectToAction("AllProducts");
}
and trying to display zip code in AllProduct view by passing it to AllProducts()
blic ActionResult AllProducts()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
if (TempData["zipcode"] == null)
{
return View();
}
else
{
var code = TempData["zipcode"];
ViewBag.codezip = code;
return View();
}
}
I am newbie to MVC and not sure why is displaying ViewBag.Message and not ViewBag.codezip
What is that I am doing wrong. Please help me out.
|
|
|
|
|
Try simplifying your GET method:
public ActionResult AllProducts()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
ViewBag.codezip = TempData["zipcode"];
return View();
}
Also make sure that you match the case when you reference the value from your view:
Zip code: @ViewBag.codezip
You shouldn't need the TempData.Keep call in your POST action, since you don't read the value until the next request.
If it still doesn't work, then there must be something else going on that we can't see.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i consult these two web site just to know how to work with soap header
https://www.codeproject.com/articles/4398/authentication-for-web-services-using-soap-headers
https://www.codeproject.com/Articles/27365/Authenticate-NET-Web-Service-with-Custom-SOAP-Head
i also develop my web service this way. see the code
namespace CustomAuthWithHTTPModule
{
public class Authentication : SoapHeader
{
public string User;
public string Password;
}
public class SecureWebService : WebService
{
public Authentication authentication;
[WebMethod]
[SoapHeader("authentication", Required = true)]
public string ValidUser()
{
if (User.IsInRole("Customer"))
return "User is in role customer";
if (User.Identity.IsAuthenticated)
return "User is a valid user";
return "not authenticated";
}
}
}
in my console apps i create the proxy of the above web service just by add web reference. the problem is AuthHeaderValue or UserCredentialsValue both property is not being expose at client side by which i can send user credentials. see my client code
ServiceReference1.SecureWebServiceSoapClient xx = new ServiceReference1.SecureWebServiceSoapClient();
ServiceReference1.Authentication a = new ServiceReference1.Authentication();
a.User = "Hello";
a.Password = "Hello";
xx.AuthHeaderValue or xx.UserCredentialsValue
guide me where i made the mistake. i am working with VS2013 IDE. thanks
tbhattacharjee
|
|
|
|
|
I did something simliar last year, in which I made a web service for a web application, that a vb.net app would access.
So on the Web Side, I made a Class but used Get Set and serialized it. And made a web service as well.
I wrote this in VB off the top of my head, I could not find any examples on how to do it and I wasn't writing C# yet.
<Serializable()>
Public Class ws_subscribersCount_Request
<pre>
Private m_Credentials_Key As String
Private m_Credentials_Password As String
Public Property Credentials_Key As String
Get
Return m_Credentials_Key
End Get
Set(value As String)
m_Credentials_Key = value
End Set
End Property
Public Property Credentials_Password As String
Get
Return m_Credentials_Password
End Get
Set(value As String)
m_Credentials_Password = value
End Set
End Property
End Class
<webmethod(enablesession:=true)> _
Public Function subscribers_count( _
ByVal SubscribersRequest As ws_subscribersCount_Request) As ws_subscribersCount_Response
Dim subscribers As New ws_subscribersCount_Response
Dim dwXCode As Integer = crm_ef_login.administrator_Login(
SubscribersRequest.Credentials_Key,
SubscribersRequest.Credentials_Password
)
If (0 = dwXCode) Then
Dim m_count As Integer = crm_ws_ef_subscribers.subscribers_Count()
If (m_count > 0) Then
subscribers.response_Code = "OK"
subscribers.response_Text = m_count & " subscribers have loaded successfully"
subscribers.count = m_count
Else
subscribers.response_Code = "E001"
subscribers.response_Text = "No subscribers exist in the database"
subscribers.count = 0
End If
Else
subscribers.response_Code = "E000"
subscribers.response_Text = "Failed Authentication"
subscribers.count = 0
End If
Return subscribers
End Function
Then on the client side, I registered a Service Reference by running the web app in debug, and then using VS to register the asmx file,
Add Service Reference
find the asmx file using a browser and copy the address, then paste the address into the client address textbox and add ? WSDL to it
http://localhost:7591/smtpMessenger.asmx?WSDL
This will turn the URL into a WSDL or SOAP class in the console app your testing or writing.
Then in the client app, this is how you handle the call
Public Shared Function get_Subscriber_Count( _
ByRef pResult As crm.ws_subscribersCount_Response) As Integer
Dim txn As New crm.ws_subscribersCount_Request
Dim credentials As New soap_credentials()
soap_credentials_io.soap_configuration_read(credentials)
Dim m_endpointUrl As String = Nothing
Dim m_serviceModel_Binding As System.ServiceModel.HttpBindingBase = Nothing
Select Case credentials.EnableSSL
Case True
m_serviceModel_Binding = New System.ServiceModel.BasicHttpsBinding()
Dim x As Integer = credentials.WebsiteUrl.LastIndexOf("//") + 2
m_endpointUrl = "https://" & credentials.WebsiteUrl.Substring(x, credentials.WebsiteUrl.Length - x)
Case False
m_serviceModel_Binding = New System.ServiceModel.BasicHttpBinding()
Dim x As Integer = credentials.WebsiteUrl.LastIndexOf("//") + 2
m_endpointUrl = "http://" & credentials.WebsiteUrl.Substring(x, credentials.WebsiteUrl.Length - x)
End Select
txn.Credentials_Key = credentials.Secure_UserName
txn.Credentials_Password = credentials.Secure_Password
Dim remoteAddress As New System.ServiceModel.EndpointAddress(m_endpointUrl)
Try
Using client As New crm.ws_smtpMessengerSoapClient(m_serviceModel_Binding, remoteAddress)
Dim responseType As New crm.ws_subscribersCount_Response
responseType = client.subscribers_count(txn)
pResult = responseType
If (pResult Is Nothing) Then
pResult = New crm.ws_subscribersCount_Response
pResult.response_Code = "E100"
pResult.response_Text = ""
End If
End Using
Catch ex As Exception
pResult = New crm.ws_subscribersCount_Response
pResult.response_Code = "ESOAP"
pResult.response_Text = ex.Message.ToString
End Try
End Function
Maybe someone could help and fix the formatting, in the past it worked great, now I struggle with it.
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
i asked different question. my problem is AuthHeaderValue or UserCredentialsValue is not getting available in my console apps
where i am consuming web service. i need to pass credentials from client side to service side.
AuthHeaderValue or UserCredentialsValue not being exposed at client side. so anyone guide me. thanks
tbhattacharjee
|
|
|
|
|
In the demo code, there are 2 objects, 1 being the web service and the other being the authentication header
In your sample code, you made the authentication object, but I don't see the web service object to bind the header data to and transmit it.
private void Page_Load(object sender, System.EventArgs e)
{
AuthWebService.WebService webService = new AuthWebService.WebService();
AuthWebService.AuthHeader authentication = new AuthWebService.AuthHeader();
authentication.Username = "test";
authentication.Password = "test";
webService.AuthHeaderValue = authentication;
DataSet dsData = webService.SensitiveData();
response string = webService.SensitiveData();
dgData.DataSource = dsData;
dgData.DataBind();
}
And I have no idea if your web service really works or not.
To test, you really need to run the web service in Debug, and when you call it, walk the code to make sure it works, and look at what is returned by the webservice before it sends the data back. If you can't walk the code, then perhaps your never really calling the web service and nothing is happening.
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
i have face the problem at this line
webService.AuthHeaderValue = authentication;
in my case AuthHeaderValue was not exposing at client side but AuthHeaderValue was public in my web service.
if possible give me the code for your web service design and i want to see how you apply soapheader attribute.
thanks a lot for reply.
tbhattacharjee
|
|
|
|
|
Mines just a class written in VB. The class is then registered on a asmx page as a single line.
The web service class uses serialized classes to package the data, and not just a couple of primitive variables.
As far as the namespace goes, never had a problem with it "redcopper.net"
I was thinking about your post last night, and realized the code the article your referencing is for authenticating using the SOAP header, in an existing SOAP operation that actually works. In other words, you have an existing SOAP application that works, but you want to authenticate in the SOAP header, before the server responds to the SOAP envelope or body of data.
You may want to consider getting the SOAP envelope working first, and then add the code to authenticate using the SOAP header.
To get the SOAP envelope working first, remove or remark out the [SoapHeader ("Authentication", Required=true)]
But ...
[SoapHeader ("Authentication", Required=true)]
This part here must activate or tell the WebMethod to analyse or process the SOAP header first, sort of like a MVC controller attribute in which because required = true, it expects the model "AuthHeader" to be present. If it's not present or does not match the format, the SOAP call is rejected.
public AuthHeader Authentication;
public class AuthHeader : SoapHeader
{
public string Username;
public string Password;
}
The class above called AuthHeader is used in the WebMethod, but must be the same exact class referenced in your console app via a WebReference. It can't be a copy of the class in your console app, in other words having 2 of them; one on the client and one on the server, it has to be the same exact class, or else it won't work.
So here is the simple client again ...
AuthWebService.WebService webService = new AuthWebService.WebService();
AuthWebService.AuthHeader authentication = new AuthWebService.AuthHeader();
authentication.Username = "test";
authentication.Password = "test";
webService.AuthHeaderValue = authentication;
DataSet dsData = webService.SensitiveData();
Regardless of how you write the SOAP code, everything on the client side must use the WebServices classes, so you create a WebReference.
In the sample project, there is a WSDL file. This file is created when you make a WebReference on the client.
If you input data into the WebReference Tool, you will then target the service end point of the service,
in this case I changed it to http://localhost:5636/AuthForWebServices/WebService.asmx to point to a debug server.
<binding name="WebServiceHttpGet" type="s0:WebServiceHttpGet">
<http:binding verb="GET" />
</binding>
<binding name="WebServiceHttpPost" type="s0:WebServiceHttpPost">
<http:binding verb="POST" />
</binding>
<service name="WebService">
<port name="WebServiceSoap" binding="s0:WebServiceSoap">
<soap:address location="http://localhost:5636/AuthForWebServices/WebService.asmx" />
</port>
<port name="WebServiceHttpGet" binding="s0:WebServiceHttpGet">
<http:address location="http://localhost:5636/AuthForWebServices/WebService.asmx" />
</port>
<port name="WebServiceHttpPost" binding="s0:WebServiceHttpPost">
<http:address location="http://localhost:5636/AuthForWebServices/WebService.asmx" />
</port>
If you can't contact the WebService, then you may have a binding or service endpoint error; that is determined by the above file.
Check and make sure your WSDL file is correct, and has the correct URL, check the HTTP or HTTPS for port 80 or 443.
The one thing I don't like about this, is that you have to change the URL when you use it in production to match the production servers URL.
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
thanks for your answer. thanks for your below code
AuthWebService.WebService webService = new AuthWebService.WebService();
AuthWebService.AuthHeader authentication = new AuthWebService.AuthHeader();
authentication.Username = "test";
authentication.Password = "test";
webService.AuthHeaderValue = authentication;
DataSet dsData = webService.SensitiveData();
i am working with VS2013. i construct my code the same way but in my case i can not pass credentials this way
webService.AuthHeaderValue = authentication;
rather i have to pass auth like this way when calling service function from client side
ServiceReference1.AuthenticateHeader oAuth = new ServiceReference1.AuthenticateHeader();
oAuth.UserName = "Test";
oAuth.Password = "Test";
ServiceReference1.Test1SoapClient oClient =new ServiceReference1.Test1SoapClient();
try
{
var o= oClient.Add(oAuth, 2, 3);
}
catch(SoapException SoapEx)
{
}
catch (Exception Ex)
{
}
tbhattacharjee
|
|
|
|
|
That looks like your spin on the code from the sample app.
You can name the Web Reference whatever you like. And you can rename the Web Reference as Well.
You can also use Fiddler to hook your program in debug and see if the data is attached in the SOAP header. Then you can isolate where your issue really lies.
You capture the request and response, and inspect the data in the right side window.
Fiddler free web debugging proxy[^]
21st Century Globalism has become Socialism on a planetary scale, in which the unequal treaties of the past have come back into play.
|
|
|
|
|
i have a asmx web service and i attached the Soap Extension just to intercept data and encrypt/decrypt it but the problem is Soap Extension ProcessMessage function not calling
here is my full code with web.config and i am running the code from VS2013.
please see my code and tell me where i made the mistake for which ProcessMessage function not calling
namespace EncryptASMX
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Test1 : System.Web.Services.WebService
{
public AuthenticateHeader Credentials;
[AuthExtension]
[SoapHeader("Credentials", Required = true)]
[WebMethod]
public string Add(int x, int y)
{
return (x + y).ToString();
}
}
public class AuthenticateHeader : SoapHeader
{
public string UserName;
public string Password;
}
[AttributeUsage(AttributeTargets.Method)]
public class AuthExtensionAttribute : SoapExtensionAttribute
{
int _priority = 1;
public override int Priority
{
get { return _priority; }
set { _priority = value; }
}
public override Type ExtensionType
{
get { return typeof(AuthExtension); }
}
}
public class AuthExtension : SoapExtension
{
public override void ProcessMessage(SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterDeserialize)
{
foreach (SoapHeader header in message.Headers)
{
if (header is AuthenticateHeader)
{
AuthenticateHeader credentials = (AuthenticateHeader)header;
if (credentials.UserName.ToLower() ==
"jeff" &&
credentials.Password.ToLower() ==
"imbatman")
return;
break;
}
}
throw new SoapException("Unauthorized",
SoapException.ClientFaultCode);
}
}
public override Object GetInitializer(Type type)
{
return GetType();
}
public override Object GetInitializer(LogicalMethodInfo info,
SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(Object initializer)
{
}
}
}
web.config entry
="1.0"
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<webServices>
<soapExtensionTypes>
<add type="EncryptASMX.AuthExtension,EncryptASMX" priority="1" />
</soapExtensionTypes>
</webServices>
</system.web>
</configuration>
i consult two links but still not configure how to run process message. here are the links
http://www.c-sharpcorner.com/article/using-soap-header-and-soap-extensions-in-a-web-service/
http://www.codeguru.com/csharp/csharp/cs_webservices/security/article.php/c5479/Build-Secure-Web-Services-With-SOAP-Headers-and-Extensions.htm
tbhattacharjee
|
|
|
|
|