I'm self-hosting a web service using WCF. The host computer has multiple ethernet ports, so I am creating the ServiceHost with multiple URIs. When I create the service host, I get the following error:
"This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item"
Following is the code:
Uri[] uriSet = new Uri[ipList.Count];
for (int i=0; i<ipList.Count; i++)
{
string baseAddress = string.Format("http://{0}:{1}/mynamespace", ipList[i], myport);
uriSet[i] = new Uri(baseAddress);
}
host = new ServiceHost(webServiceType, uriSet);
ipList contains the list of IP addresses for the host computer.
You can use the special IP address 0.0.0.0 or just localhost to match any IP address for the local machine. Therefore, you should only need one base address URI, with either localhost or 0.0.0.0.
host = new ServiceHost(webServiceType, new Uri[] { new Uri("http://localhost:80/mynamespace") });
or
host = new ServiceHost(webServiceType, new Uri[] { new Uri("http://0.0.0.0:80/mynamespace") });
* where 80 is the port.
https://msdn.microsoft.com/en-us/library/ms733768%28v=vs.110%29.aspx
Related
I'm using the following code to set the proxy for the HTMLSession, get() method. Still, it uses my IP instead of the proxy IP.
proxy string format:
http://username:password#ip:port
r = session.get('https://whatismyipaddress.com/', proxies={'http': proxy})
r.html.find('p.ip-address')[0].text
above print the following which is my current IP address.
'IPv4:? The most common IP version is assigned by ISPs. 175.157.?.?'
You need to add 'https' in proxies:
proxy = 'http://username:password#ip:port'
r = session.get('https://whatismyipaddress.com/', proxies={'http': proxy, 'https': proxy})
i tried to connect REST web servie from windows phone 8 application.
it was working proberly for weeks but after no change in it I get this generic error :
System.Net.WebException: The remote server returned an error:
NotFound.
i tried to test it by online REST Clients and services works properly
i tried to handle Exception and parse it as webException by this code :
var we = ex.InnerException as WebException;
if (we != null)
{
var resp = we.Response as HttpWebResponse;
response.StatusCode = resp.StatusCode;
and i get no more information and final response code is : "NotFound"
any one have any idea about what may cause this error?
there is already a trusted Certificate implemented on the server . the one who has the server suggested to have a DNS entry for the server, this entry should be at the customer DNS or in the phone hosts file .that what i done and worked for awhile but now it doesn't work however i checked that there is no thing changed
this is sample for Get Request it works proberly on Windwos Store apps :
async Task<object> GetHttps(string uri, string parRequest, Type returnType, params string[] parameters)
{
try
{
string strRequest = ConstructRequest(parRequest, parameters);
string encodedRequest = HttpUtility.UrlEncode(strRequest);
string requestURL = BackEndURL + uri + encodedRequest;
HttpWebRequest request = HttpWebRequest.Create(new Uri(requestURL, UriKind.Absolute)) as HttpWebRequest;
request.Headers["applicationName"] = AppName;
request.Headers["applicationPassword"] = AppPassword;
if (AppVersion > 1)
request.Headers["applicationVersion"] = AppVersion.ToString();
request.Method = "GET";
request.CookieContainer = cookieContainer;
var factory = new TaskFactory();
var getResponseTask = factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
HttpWebResponse response = await getResponseTask as HttpWebResponse;
// string s = response.GetResponseStream().ToString();
if (response.StatusCode == HttpStatusCode.OK)
{
XmlSerializer serializer = new XmlSerializer(returnType);
object obj = serializer.Deserialize(response.GetResponseStream());
return obj;
}
else
{
var Instance = Activator.CreateInstance(returnType);
(Instance as ResponseBase).NetworkError = true;
(Instance as ResponseBase).StatusCode = response.StatusCode;
return Instance;
}
}
catch (Exception ex)
{
return HandleException(ex, returnType);
}
}
i tried to monitor connections from Emulator and i found this error in connection :
**
Authentication failed because the remote party has closed the
transport stream.
**
You saw the client implement a server side certificate in the service. Did you have that certificate installed on the phone? That can be the cause of the NotFound error. Please, can you try to navigate to the service in the phone or emulator internet explorer prior to testing the app? If you do that, you can see the service working in the emulator/phone internet explorer? Maybe at that point internet explorer ask you about installing the certificate and then you can open your app, and it works.
Also remember if you are testing this in the emulator, every time you close it, the state is lost so you need to repeat the operation of installing the certificate again.
Hope this helps.
If you plan to use SSL in production in general public application (not company-distribution app), you need to ensure your certificate has one of the following root authorities:
SSL root certificates for Windows Phone OS 7.1.
When we had same issue, we purchased SSL certificate from one of those providers and after installing it on server we were able to make HTTPS requests to our services with no problem.
If you have company-distribution app, you can use any certificate from company's Root CA.
i need to capture some packet data that are being sent to a particular IP of web-server by a GPRS module. i am using rest web service for the capture of packet data. i'm new to this so pardon the stupidities; my doubt was that can we directly access the packet data to a string using #GET annotation to that particular url or should I define a server socket function inside #GET annotation and then listen to it?
i think we should provide server socket function inside #GET annotation.
Like;
#GET
#Path("/hello/path")
public String hello(#PathParam("path") String val) {
ServerSocket server = new ServerSocket(6608);
Socket socket = null;
socket = phone.accept();
InputStream in = socket.getInputStream();
din = new DataInputStream(in);
}
I am trying to use GeoIP, but I have a problem when I use REMOTE_ADDR. The IP shown is that of my server and not the client.
from django.contrib.gis.geoip import GeoIP
Example context:
g = GeoIP()
ip = self.request.META.get('REMOTE_ADDR')
context['my_ip'] = ip # this display ip client
context['pais_anuncio'] = g.country_code('ip') # this display ip my server.
What am I doing wrong, Thank you.
My guess is, since you are passing the string 'ip', it is defaulting to your server's IP. Try passing in the variable ip, like this:
context['pais_anuncio'] = g.country_code(ip)
I'm trying to execute a program that is on machine B (Part of a domain) from machine A (Not part of domain). I've the following code and throws "The RPC Server is unavailable" when I tried to use a domain user that is part of machine B's Administrators group. When I use the local user "administrator" which is also part of Machine B's Administrators group, the code works fine.
Firewall is disabled on both the machines. I could logon to machine B from machine A using both the users.
Could you help me with it?
ConnectionOptions connectionOptions = new ConnectionOptions();
connectionOptions.Authority = "kerberos:" + domain + #"\" + machine;
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connectionOptions.Username = username;
connectionOptions.Password = password;
ManagementScope scope = new ManagementScope(#"\\" + machine + "." + domain + #"\root\CIMV2", connectionOptions);
ManagementPath p = new ManagementPath("Win32_Process");
ManagementClass classInstance = new ManagementClass(scope, p, null);
ManagementClass startupSettings = new ManagementClass("Win32_ProcessStartup");
startupSettings.Scope = scope;
startupSettings["CreateFlags"] = 16777216;
I could sort the problem out. The domain controller was not accessible. Also, both public and private IPs were configured to my machine. The private IP was the primary and public was secondary. I needed to use them accordingly when needed.